无法通过适用于Android的Google+登录获取授权码:INVALID_SCOPE

Nac*_*oma 5 android google-play-services google-oauth

我正在尝试按照这些说明检索要在我的服务器端使用的授权代码.服务器的客户端ID共享我的Android客户端ID的同一项目.

我可以检索访问令牌,但不能检索授权代码:

String mScopes = "oauth2:https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email";
//String mScopes = "oauth2:server:client_id:314345278679.apps.googleusercontent.com:api_scope:https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email";
Bundle mAppActivities = new Bundle();
mAppActivities.putString(GoogleAuthUtil.KEY_REQUEST_VISIBLE_ACTIVITIES, "");
String authorizationToken = GoogleAuthUtil.getToken(LoginActivity.this, mPlusClient.getAccountName(), mScopes, mAppActivities);
Run Code Online (Sandbox Code Playgroud)

取消注释以使用替代范围(检索授权代码而不是令牌)会产生以下错误:

I/GLSUser (15293): GLS error: INVALID_SCOPE my_email_address@company.com oauth2:server:client_id:314345278679.apps.googleusercontent.com:api_scope:https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

Lee*_*Lee 11

您缺少来自示波器的https://www.googleapis.com/auth/plus.login.我尝试了你的代码并获得INVALID_SCOPE而没有plus.login,但它可以正常工作.

  • 嘿@Lee,这曾经为我工作,但仅在几天前它停止工作,现在它抛出了这个错误com.google.android.gms.auth.GoogleAuthException:Unknown.知道为什么吗?我的示波器有问题吗?https://gist.github.com/lawloretienne/7351151 (3认同)