“Google凭证无效”Google plus with request/plus/v1/people/me
问题描述:
我正在使用Google+登录,并且始终正确收到令牌,但是当我想通过此令牌通过“https://www.googleapis.com/plus/v1/people/me”卷曲。我总是得到同样的错误。“Google凭证无效”Google plus with request/plus/v1/people/me
代码的Android进行登录:
// Scope to get the token with the user information
public static final String SCOPE_GOOGLE_USER_INFORMATION = "https://www.googleapis.com/auth/userinfo.profile";
public static final String SCOPE_GOOGLE_PLUS_ME = "https://www.googleapis.com/auth/plus.me";
public static final String SCOPE_GOOGLE_PLUS_LOGIN = "https://www.googleapis.com/auth/plus.login";
public static final String SCOPE_GOOGLE_PLUS_EMAIL = "https://www.googleapis.com/auth/userinfo.email";
public static final String SCOPE = "oauth2:" + SCOPE_GOOGLE_USER_INFORMATION + " " + SCOPE_GOOGLE_PLUS_ME + " " + SCOPE_GOOGLE_PLUS_LOGIN + " " + SCOPE_GOOGLE_PLUS_EMAIL;
String token = GoogleAuthUtil.getToken(activity, userEmail, SCOPE);
然后我做出卷曲要求:
curl -H "Authorization: Bearer TOKEN" https://www.googleapis.com/plus/v1/people/me?key={KEY}
总是我收到了同样的错误:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
,但如果我这样做通过https://developers.google.com/oauthplayground/作品
答
您的密钥和访问令牌必须来自同一个项目。您可以通过将访问令牌的项目编号插入来检查项目编号:https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=
删除plus.me作用域也是不需要的。电子邮件和配置文件范围可分别替换为字符串“email”和“profile”(不包括https://wwww.googleapis.com等)。 plus.login是合理的,但如果你只是获得基本的配置文件,你不需要它 - 配置文件范围会给你从plus API。
有一点,当人们在同一请求中包含不记名令牌和密钥时,他们会遇到问题。如果您删除密钥会发生什么? – abraham 2015-03-30 23:38:37
我无法删除密钥,因为如果没有我收到其他错误。 { “错误”:{ “错误”:[ { “域”: “usageLimits”, “原因”: “accessNotConfigured”, “消息”:“访问未配置API上(Google API)是“, ”extendedHelp“:”https://console.developers.google.com“ } ], ”code“:403, “message”:“Access Not Configured。API(Google + API)未启用您的项目,请使用Google Developers Console更新您的配置。” } } – TeRRo 2015-03-31 08:03:31
听起来好像不记名代币是从没有启用Google+项目的项目中生成的。 – abraham 2015-03-31 14:50:41