【问题标题】:Get access token for my application from the GoogleApiClient in Android从 Android 中的 GoogleApiClient 获取我的应用程序的访问令牌
【发布时间】:2014-09-27 22:11:10
【问题描述】:

我目前正在开发一个应用程序,并且我已经在其中集成了 GooglePlus Api。我的应用程序使用谷歌帐户成功登录,但我无法获取访问令牌。我按照 developer.google.com 提供的步骤以及针对 Stackoverflow 中发布的类似问题提供的解决方案进行操作。

例如。

 AsyncTask<Void, Void, String> task = new AsyncTask<Void, Void, String>() {
            @Override
            protected String doInBackground(Void... params) {
                String token = null;

                try {
                    token = GoogleAuthUtil.getToken(
                            MainActivity.this,
                            mGoogleApiClient.getAccountName(),
                            "oauth2:" + SCOPES);
                } catch (IOException transientEx) {
                    // Network or server error, try later
                    Log.e(TAG, transientEx.toString());
                } catch (UserRecoverableAuthException e) {
                    // Recover (with e.getIntent())
                    Log.e(TAG, e.toString());
                    Intent recover = e.getIntent();
                    startActivityForResult(recover, REQUEST_CODE_TOKEN_AUTH);
                } catch (GoogleAuthException authEx) {
                    // The call is not ever expected to succeed
                    // assuming you have already verified that 
                    // Google Play services is installed.
                    Log.e(TAG, authEx.toString());
                }

                return token;
            }

            @Override
            protected void onPostExecute(String token) {
                Log.i(TAG, "Access token retrieved:" + token);
            }

        };
        task.execute();

mGoogleApiClient.getAccountName() 方法不适合我(即当我输入 mGoogleApiClient. 时,没有这样的方法称为 getAccountName() 可供选择)。 这是因为我在片段中实现了 GoogleApi 吗?或

这有什么原因吗。

请帮我解决这个问题。 谢谢你

【问题讨论】:

    标签: android google-plus access-token


    【解决方案1】:

    我终于找到了我要找的东西,我用 Plus.AccountApi.getAccountName(mGoogleApiClient) 而不是 mGoogleApiClient.getAccountName() 并且成功了。

    【讨论】:

      猜你喜欢
      • 2012-05-04
      • 2011-09-21
      • 2016-01-18
      • 1970-01-01
      • 1970-01-01
      • 2017-12-24
      • 2013-08-05
      • 2017-04-11
      • 1970-01-01
      相关资源
      最近更新 更多