gpt4 book ai didi

android - PersonAPI Google+ "PERMISSION_DENIED"错误

转载 作者:行者123 更新时间:2023-11-29 19:30:05 29 4
gpt4 key购买 nike

我正在尝试使用 Google+ 提供的 PersonAPI 获取性别和出生日期,但我在日志中收到服务器端错误。

这是我的 Logcat:

com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
"code" : 403,
"errors" : [ {
"domain" : "global",
"message" : "Request had insufficient authentication scopes.",
"reason" : "forbidden"
} ],
"message" : "Request had insufficient authentication scopes.",
"status" : "PERMISSION_DENIED"
}

我正在使用以下代码:

ListConnectionsResponse response = peopleService.people().connections()
.list("people/me")
.execute();

请告诉我我错过了什么?非常感谢任何帮助。

最佳答案

您必须在发送任何 Google API 请求之前授权。也就是说,

 GoogleSignInOptions signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
// The serverClientId is an OAuth 2.0 web client ID
.requestServerAuthCode(getString(R.string.clientID))
.requestEmail()
.requestScopes(new Scope(Scopes.PLUS_LOGIN),
new Scope(PeopleScopes.CONTACTS_READONLY),
new Scope(PeopleScopes.USER_EMAILS_READ),
new Scope(PeopleScopes.USERINFO_EMAIL),
new Scope(PeopleScopes.USER_PHONENUMBERS_READ))
.build();


// To connect with Google Play Services and Sign In
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this)
.addOnConnectionFailedListener(this)
.addConnectionCallbacks(this)
.addApi(Auth.GOOGLE_SIGN_IN_API, signInOptions)
.build();

并捕获成功回调:

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

switch (requestCode) {
case RC_INTENT:
Log.d(TAG, "sign in result");
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);

if (result.isSuccess()) {
GoogleSignInAccount acct = result.getSignInAccount();
Log.d(TAG, "onActivityResult:GET_TOKEN:success:" + result.getStatus().isSuccess());
// This is what we need to exchange with the server.
Log.d(TAG, "auth Code:" + acct.getServerAuthCode());

// PUT YOUR WANTED CODE HERE


} else {

Log.d(TAG, result.getStatus().toString() + "\nmsg: " + result.getStatus().getStatusMessage());
}
break;

}
}

关于android - PersonAPI Google+ "PERMISSION_DENIED"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40218483/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com