安卓的Google+无法获得身份验证code [英] Android Google+ unable to get auth code

查看:162
本文介绍了安卓的Google+无法获得身份验证code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让基于这篇文章是Google+权威性code:<一href="https://developers.google.com/+/mobile/android/sign-in#server-side_access_for_your_app">Server-side访问你的应用。但是,每当我跑我的应用程序,并得到了code我得到了LogCat中以下内容:

  07-23 23:42:31.760:E / getAccessToken()(11114):[错误] GoogleAuthException:com.google.android.gms.auth.GoogleAuthException:未知
 

我浏览了很多东西,从我可以告诉我正确地拥有了一切建立在code以下。任何想法,为什么它没有获得一个身份验证令牌?

仅供参考,我在API控制台既有的应用程序和配置的OAuth和我使用的服务器(而不是应用程序)的ID为范围字符串的Web应用程序之一的项目设置。我也跟着例子(S)从上面的链接和应用程序正常工作,并允许您登录进/出,但我只是不能在auth code。

 私人字符串getAccessToken(){
    字符串scopesString = Scopes.PLUS_LOGIN ++ Scopes.PLUS_PROFILE;
    字符串范围=oauth2:服务器:CLIENT_ID:+ SERVER_CLIENT_ID +:api_scope:+ scopesString;
    捆绑appActivities =新包();
    appActivities.putString(GoogleAuthUtil.KEY_REQUEST_VISIBLE_ACTIVITIES,
            http://schemas.google.com/AddActivity);
    字符串code = NULL;
    尝试 {
         code = GoogleAuthUtil.getToken(
                    对此,//上下文语境
                    mPlusClient.getAccountName(),//串帐户名
                    范围,//字符串范围
                    appActivities //捆绑包
                );
    }赶上(IOException异常transientEx){
      //网络或服务器错误,看涨预期成功,如果您稍后重试。
      //不要试图立即重新调用 - 请求可能
      //失败,你会击中配额或退避。
        Log.e(getAccessToken(),[错误] IOException异常:+ transientEx);
        返回null;
    }赶上(UserRecoverableAuthException E){
           // 恢复
        Log.e(getAccessToken(),[错误] UserRecoverableAuthException:+ E);
        code = NULL;
    }赶上(GoogleAuthException authEx){
      // 失败。呼叫预计不会永远成功,所以它不应该是
      //重试。
        Log.e(getAccessToken(),[错误] GoogleAuthException:+ authEx);
      返回null;
    }赶上(例外五){
        Log.e(getAccessToken(),[错误]异常:+ E);
      抛出新的RuntimeException(E);
    }
    返回code;
}
 

解决方案

我不知道,如果你修改了行邮专列的问题,而是着眼于code您发布,这条线是错误的:

 字符串范围=oauth2:服务器:CLIENT_ID:其中,我的服务器客户端ID&GT;:scopesString;
 

这应该是:

 字符串范围=oauth2:服务器:CLIENT_ID:+ SERVER_CLIENT_ID +:api_scope:+ scopeString;
 

I'm trying to get a Google+ auth code based on this article: Server-side access for your app. However, whenever I run my app and try to get the code I get the following in LogCat:

07-23 23:42:31.760: E/getAccessToken()(11114): [ERROR] GoogleAuthException: com.google.android.gms.auth.GoogleAuthException: Unknown

I browsed a lot of stuff and from what I can tell I have everything setup correctly in the code below. Any ideas why it's not getting an auth token?

FYI, I have one project setup in the API console that has both the app and web applications configured for oauth and I'm using the server (not the app) ID for the scopes string. I've also followed the example(s) from the above link and the app works fine and allows you to sign-in/out, but I just can't get the auth code.

private String getAccessToken() {
    String scopesString = Scopes.PLUS_LOGIN + " " + Scopes.PLUS_PROFILE;
    String scope = "oauth2:server:client_id:" + SERVER_CLIENT_ID + ":api_scope:" + scopesString;
    Bundle appActivities = new Bundle();
    appActivities.putString(GoogleAuthUtil.KEY_REQUEST_VISIBLE_ACTIVITIES,
            "http://schemas.google.com/AddActivity");
    String code = null;
    try {
         code = GoogleAuthUtil.getToken(
                    this,                             // Context context
                    mPlusClient.getAccountName(),     // String accountName
                    scopes,                           // String scope
                    appActivities                     // Bundle bundle
                );
    } catch (IOException transientEx) {
      // network or server error, the call is expected to succeed if you try again later.
      // Don't attempt to call again immediately - the request is likely to
      // fail, you'll hit quotas or back-off.
        Log.e("getAccessToken()", "[ERROR] IOException: " + transientEx);
        return null;
    } catch (UserRecoverableAuthException e) {
           // Recover
        Log.e("getAccessToken()", "[ERROR] UserRecoverableAuthException: " + e);
        code = null;
    } catch (GoogleAuthException authEx) {
      // Failure. The call is not expected to ever succeed so it should not be
      // retried.
        Log.e("getAccessToken()", "[ERROR] GoogleAuthException: " + authEx);
      return null;
    } catch (Exception e) {
        Log.e("getAccessToken()", "[ERROR] Exception: " + e);
      throw new RuntimeException(e);
    }
    return code;
}

解决方案

I don't know if you modified the line to post the question but looking at the code you posted, this line is wrong:

String scopes = "oauth2:server:client_id:<My server client ID>:scopesString";

It should be:

String scopes = "oauth2:server:client_id:" + SERVER_CLIENT_ID + ":api_scope:" + scopeString;

这篇关于安卓的Google+无法获得身份验证code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆