我按照本手册将 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 );
onActivityResult 代码是:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
...
}
我不断收到 DEVELOPER_ERROR 结果。
该应用程序由我在开发者控制台中设置的 SHA1 指纹代码签名。
OAUTH 客户端 ID 取自我的应用程序的“Web 客户端”JSON 配置。
所有 API 都在 Google 开发者控制台中启用
如果我删除方法 .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();
的结果
Auth.GoogleSignInApi.getSignInResultFromIntent(data);
成功:应用程序正在请求许可。
我做错了什么?
为什么 requestServerAuthCode 会导致 DEVELOPER_ERROR,尽管 Google 手册中有一个使用此方法的示例:
是否有任何示例如何在 Android 应用程序中使用 People API?