我需要访问访问令牌并将其发送到服务器。使用该访问令牌服务器应获取所有用户详细信息,如名称,配置文件图片和电子邮件。

我可以使用 scopes.plus_login scopes.plus_me ,但是使用该访问令牌服务器无法获取用户电子邮件。

这是我的代码:

@Override
public void onConnected(Bundle arg0) {
    mSignInClicked = false;


    AsyncTask<Void, Void, String> task = new AsyncTask<Void, Void, String>() {
        @Override
        protected String doInBackground(Void... params) {
            String token = null;
            String scope = "oauth2:" + Scopes.PLUS_LOGIN + " " + Scopes.PLUS_ME;
            try {
                token = GoogleAuthUtil.getToken(
                        getApplicationContext(),
                        Plus.AccountApi.getAccountName(mGoogleApiClient),
                        scope);
                appUser.setToken(token);
            } catch (IOException transientEx) {
                // Network or server error, try later
                Log.e(TAG, transientEx.toString());
            } catch (UserRecoverableAuthException e) {
                // Recover (with e.getIntent())                
            } catch (GoogleAuthException authEx) {
                // The call is not ever expected to succeed
                // assuming you have already verified that 
                // Google Play services is installed.
                Log.e(TAG, authEx.toString());
            }

            return token;
        }

        @Override
        protected void onPostExecute(String token) {
            Log.i(TAG, "Access token retrieved:" + appUser.getToken());
            // Get user's information
        }

    };


}
.

有人知道如何解决这个问题吗?

有帮助吗?

解决方案

你错过了范围

https://www.googleapis.com/auth/userinfo.email  
.

我测试了另一个范围,只有那个似乎返回用户的电子邮件。您可以测试不同的范围以及它们在此处返回的内容:人:Get

注意:我不是一个Android程序员,你可能会有更好的运气,了解如何用Android请求该范围。我正在寻找,但没有能够找到它。

看起来似乎可能只是通过电子邮件 https://developers.google.com/+ / api / oauth#电子邮件

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top