android - 从谷歌和 Android 获取访问 token

标签 android google-plus

谁能告诉我我做错了什么?我需要从 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 请求放在后台线程中。我已经发布了一些示例代码,展示了如何在这个问题中做到这一点:

"Calling this from your main thread can lead to deadlock and/or ANRs while getting accesToken" from GoogleAuthUtil(Google Plus integration in Android)

关于android - 从谷歌和 Android 获取访问 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18096934/

相关文章:

Android - 如何检测来电是否被重定向?

javascript - 无法嵌入 google plus 帖子

javascript - 在抑制 Google+ 登录 "Welcome Back"消息后触发时,Google+ 交互式帖子不可见

cordova - 如何刷新 google+ 身份验证 token 以进行 S3 访问

android - Android 中的 Google Plus 封面照片

android - 将 Activity 之间的数据传递给 dialogfragment

java - 如何在 Android 的 Sqlite 数据库中插入 Enum 数据?

android RelativeLayout,等间距?

javascript - google+ api 人的 friend

Android ActionBar NullPointerException