请求服务器身份验证代码时,GoogleSignInResult在Android应用中返回DEVELOPER_ERROR

vma*_*row 5 android oauth google-api google-signin google-people

我正在按照此手册将Google People API连接到Android应用程序:http : //blog.iamsuleiman.com/people-api-android-tutorial-1/

我正在使用以下代码登录:

GoogleSignInOptions signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
        .requestEmail()
        .requestScopes(new Scope(Scopes.PLUS_LOGIN),
                new Scope(PeopleScopes.CONTACTS_READONLY),
                new Scope(PeopleScopes.USER_PHONENUMBERS_READ))
        .requestServerAuthCode(getString(R.string.google_oauth_client_id), false)
        .build();

    mGoogleApiClient = new GoogleApiClient.Builder(getContext())
            .enableAutoManage(getActivity(), this)
            .addApi(Auth.GOOGLE_SIGN_IN_API, signInOptions)
            .build();

    Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent( mGoogleApiClient );
    startActivityForResult( signInIntent, GOOGLE_PLUS_RC_SIGN_IN );
Run Code Online (Sandbox Code Playgroud)

onActivityResult代码为:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
    ...
}
Run Code Online (Sandbox Code Playgroud)

我一直得到DEVELOPER_ERROR的结果。

该应用程序由我在开发人员控制台中设置的SHA1指纹的代码签名。

OAUTH客户端ID来自我应用程序的“ Web客户端” JSON配置。

在Google开发人员控制台中启用了所有API

如果删除方法.requestServerAuthCode():

    GoogleSignInOptions signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .requestScopes(new Scope(Scopes.PLUS_LOGIN),
                    new Scope(PeopleScopes.CONTACTS_READONLY),
                    new Scope(PeopleScopes.USER_PHONENUMBERS_READ))
            .build();
Run Code Online (Sandbox Code Playgroud)

的结果

Auth.GoogleSignInApi.getSignInResultFromIntent(data);

成功:应用程序正在请求许可。

我做错了什么?

尽管在Google手册中有使用此方法的示例,为什么requestServerAuthCode会引起DEVELOPER_ERROR:

https://developers.google.com/identity/sign-in/android/offline-access#enable_server-side_api_access_for_your_app

是否有示例如何在Android应用中使用People API?

Jas*_*ler 0

而不是将您的生产/调试 client_id 传递到

.requestServerAuthCode()

方法使用 Web client_id 代替 - 我认为 google 登录将始终使用string.xml 中的server_client_id 。

因此从技术上讲,您需要使用两个密钥。