谁能告诉我我做错了什么?我需要从 Google Plus 获取访问 token ..
我将它放在我的 onConnected()
方法中,但我没有获得访问 token ,而是出现错误...
代码:
try {
String token = GoogleAuthUtil.getToken(this, mPlusClient.getAccountName() + "", "oauth2:" + Scopes.PLUS_PROFILE +
"https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email");
Log.d("AccessToken", token);
} catch (UserRecoverableAuthException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (GoogleAuthException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
错误:
08-07 10:10:24.199: E/GoogleAuthUtil(17203): Calling this from your main thread can lead to deadlock and/or ANRs
谁能告诉我从用户那里获取 Google Plus 访问 token 的正确方法是什么?
最佳答案
您需要将 token 请求放在后台线程中。我已经发布了一些示例代码,展示了如何在这个问题中做到这一点:
关于android - 从谷歌和 Android 获取访问 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18096934/