GoogleAuthUtil.getToken()未返回

时间:2014-01-01 23:32:26

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

在我的Android应用程序中,我正在尝试使用Google令牌连接到Google Spreadsheets。这是执行此操作的代码:

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

有人可以帮我弄清楚这个错误发生的原因吗?

1 个答案:

答案 0 :(得分:1)

看起来像范围:

  

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

 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