【问题标题】:GoogleAuthUtil.getToken() is not returningGoogleAuthUtil.getToken() 没有返回
【发布时间】:2014-01-01 23:32:25
【问题描述】:

在我的 Android 应用程序中,我试图让 Google 令牌连接到 Google 电子表格。这是执行此操作的代码:

AsyncTask<String, Void, String> getTokenTask = new AsyncTask<String, Void, String>() {

    @Override
    protected String doInBackground(String... params) {
        Log.i("Groceryviewer", "doInBackground() - Entry");
        String accountName = params[0];
        String token = null;
        try {
            Log.i("Groceryviewer", "Before get token");
            token = GoogleAuthUtil.getToken(LoginHomeActivity.this, accountName, "https://spreadsheets.google.com/feeds https://docs.google.com/feeds");
            Log.i("Groceryviewer", "After get token. Token: " + token);
        } catch (UserRecoverableAuthException e) {
            Log.e("Groceryviewer", "Exception in getToken() - UserRecoverableAuthException", e);
            Log.i("Groceryviewer", "Exception in getToken() - startActivityForResult");
            startActivityForResult(e.getIntent(), USER_ACCEPTS);
        } catch (IOException e) {
            Log.e("Groceryviewer", "Exception in getToken() - IOException", e);
        } catch (GoogleAuthException e) {
            Log.e("Groceryviewer", "Exception in getToken() - GoogleAuthException", e);
        }
        Log.i("Groceryviewer", "doInBackground() - Exit");
        return token;
    }

};
getTokenTask.execute(accountName);

String token = null;
try {
    token = getTokenTask.get();
} catch(ExecutionException e) {
    Log.i("Groceryviewer", "Exception in get() - ExecutionException", e);
} catch (InterruptedException e) {
    Log.i("Groceryviewer", "Exception in get() - InterruptedException", e);
}
Log.i("Groceryviewer", "Token: " + token);

我也将此添加到 AndroidManifest.xml 中:

<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

问题是 getToken 根本不返回。这是我的日志:

01-01 17:28:57.583: I/Groceryviewer(1485): doInBackground() - Entry
01-01 17:28:57.583: I/Groceryviewer(1485): Before get token

谁能帮我弄清楚为什么会发生这个错误?

【问题讨论】:

  • 我使用了谷歌 DrEdit 教程来让它工作 (OAuth2)。我搜索了很长时间以找到更好的东西,但“DrEdit”是我能找到的最好的,(我使用 AppEngine 而不是 android)。

标签: android google-sheets google-spreadsheet-api


【解决方案1】:

看起来像范围:

实际上你只需要使用一个方法调用, GoogleAuthUtil.getToken()。它需要三个参数:一个上下文,一个 电子邮件地址和另一个称为范围的字符串参数。

 private final static String G_SPREADSHEET_SCOPE = 
  "oauth2:https://docs.google.com/feeds/ https://docs.googleusercontent.com/ https://spreadsheets.google.com/feeds/";

http://android-developers.blogspot.com.au/2012/09/google-play-services-and-oauth-identity.html

【讨论】:

猜你喜欢
  • 2015-08-03
  • 2015-03-28
  • 1970-01-01
  • 2013-12-04
  • 2014-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多