gpt4 book ai didi

android - GoogleAuthUtil.getToken() 没有返回

转载 作者:行者123 更新时间:2023-11-29 01:47:01 26 4
gpt4 key购买 nike

在我的 Android 应用程序中,我试图获取 Google token 以连接到 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

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

最佳答案

看起来像范围:

There’s really only one method call you need to use, GoogleAuthUtil.getToken(). It takes three arguments: a Context, an email address, and another string argument called 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

关于android - GoogleAuthUtil.getToken() 没有返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20874386/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com