获得访问令牌来自谷歌Android的加令牌、Android

2023-09-06 00:29:30 作者:怕,你就输了

谁能告诉我我究竟做错了什么?我需要从谷歌加访问令牌。

Can anyone tell me what am I doing wrong? I need to get the access token from Google Plus..

我把这个在我的 onConnected()方法,但我没有收到访问令牌,而是我得到错误...

I put this in my onConnected() method but I am not getting the access token, instead I am getting error...

code:

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

谁能告诉我什么是正确的方式来获得用户的谷歌加访问令牌?

Can anyone tell me what would be the correct way to get the Google Plus access token from the user?

推荐答案

您需要把请求在后台线程的令牌。我已经发布了一些例如code,展示了如何做,在这个问题:

You need to put the request for a token in a background thread. I've posted some example code showing how to do it in this question:

"Calling这从你的主线程可能导致死锁和/或ANRS同时获得accesToken"从GoogleAuthUtil(谷歌加集成在Android中)