Android谷歌无法获得授权代码

Android谷歌无法获得授权代码,第1张

概述我正在尝试根据这篇文章获得Google身份验证代码: Server-side access for your app.但是,每当我运行我的应用程序并尝试获取代码时,我在LogCat中获得以下内容: 07-23 23:42:31.760: E/getAccessToken()(11114): [ERROR] GoogleAuthException: com.google.android.gms.au 我正在尝试根据这篇文章获得Google身份验证代码: Server-side access for your app.但是,每当我运行我的应用程序并尝试获取代码时,我在LogCat中获得以下内容:
07-23 23:42:31.760: E/getAccesstoken()(11114): [ERROR] GoogleAuthException: com.Google.androID.gms.auth.GoogleAuthException: UnkNown

我浏览了很多东西,据我所知,我已经在下面的代码中正确设置了所有内容.任何想法为什么它没有获得身份验证令牌?

仅供参考,我在API控制台中有一个项目设置,其中包含为oauth配置的应用程序和Web应用程序,而我正在使用作用域字符串的服务器(而不是应用程序)ID.我也跟着上面链接中的示例,应用程序工作正常,允许您登录/退出,但我无法获得身份验证代码.

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;}
解决方法 我不知道你是否修改过该行以发布问题,但查看你发布的代码,这一行是错误的:
String scopes = "oauth2:server:clIEnt_ID:<My server clIEnt ID>:scopesstring";

它应该是:

String scopes = "oauth2:server:clIEnt_ID:" + SERVER_CLIENT_ID + ":API_scope:" + scopestring;
总结

以上是内存溢出为你收集整理的Android谷歌无法获得授权代码全部内容,希望文章能够帮你解决Android谷歌无法获得授权代码所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1135810.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存