Android Google Login Auth NeedPermission问题

标签 android google-api google-signin

我现在正在我的应用程序中添加谷歌登录。但是我得到了来自这个范围 scope = "oauth2:"+ Scopes.PLUS_LOGIN 的 token ,但是服务器无法通过该 token 获取用户的电子邮件。所以我用一个空格添加了我的范围“https://www.googleapis.com/auth/userinfo.email”。但我只收到系统错误。像这样

06-19 15:26:33.444 25229-25460/ W/System.err﹕ com.google.android.gms.auth.UserRecoverableAuthException: NeedPermission 06-19 15:26:33.445 25229-25460/ W/System.err﹕ at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source) 06-19 15:26:33.447 25229-25460/ W/System.err﹕ at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)

我完全不明白我需要什么样的许可。 这也是我的代码。

AsyncTask task = new AsyncTask() {
    @Override
    protected Object doInBackground(Object... params) {
        final String CLIENT_ID = "abc123.apps.googleusercontent.com";
        final List<String> SCOPES = Arrays.asList(new String[]{
            "https://www.googleapis.com/auth/plus.login",
            "https://www.googleapis.com/auth/userinfo.email"
        });
        try {
            String scopes = String.format("oauth2:server:client_id:%s:api_scope:%s", CLIENT_ID , TextUtils.join(" ", SCOPES));
            String token = GoogleAuthUtil.getToken(context, Plus.AccountApi.getAccountName(mGoogleApiClient), scopes);
            userInfo = new GoogleUserInfo(email, finalPersonPhotoUrl, currentPerson.getId(), token, currentPerson.getDisplayName());`enter code here`
        }
        catch (UserRecoverableAuthException e) {
            // This error is recoverable, so we could fix this
            // by displaying the intent to the user.
            e.printStackTrace();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        catch (GoogleAuthException e) {
            e.printStackTrace();
        }
        return null;
        }
    };
task.execute((Void) null);

我怎样才能拥有可以通过电子邮件获取用户信息的 token ? ? ?

最佳答案

我试了很多方法都不行,所以我收到了这样的邮件

String email = Plus.AccountApi.getAccountName(GoogleApiClient);

其他用户信息,调用Plus.PeopleApi.getCurrentPerson即可获取

关于Android Google Login Auth NeedPermission问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24352211/

相关文章:

java - 排序 ListView 时不调用比较方法

php - 使用带有php脚本的google drive api自动刷新 token

php - google-api-php-client-0.5.0 回调网址?

google-api - 谷歌 oAuth "expiry_date"格式

javascript - 谷歌登录/第三方身份验证提供商

java - list 合并失败?建议覆盖 :add'tools:replace ="android:appComponentFactory"'to<application>element at AndroidManifest. xml:8:5-34:19

android - ListView onScrollChanged 总是返回 0

android - GoogleSignInAccount getPhotoUrl() 返回 null

android - 错误 : Cannot fit requested classes in a single dex file (# methods: 65978 > 65536)

android - 将 unsigned long long 转换为等效的 jni 数据类型?