Google Plus使用访问令牌进行整合 [英] Google plus intergration using access token
问题描述
在我的Android应用程序中,我需要集成Google+登录.我已经尝试过这种方法,并且能够成功获取访问令牌.但是,在传递到我的Web服务时,我无法在访问令牌中获取电子邮件地址.
In my android application i need to integrate Google+ sign in. I have tried by this method and i can able to get access token successfully. But i can't able to get email address in my access token, while passing into my web service.
过去三天我都在使用Google,但我已经尝试了很多方法,但都没有找到解决问题的方法.我尝试了所有作用域,但我在访问令牌中未获得电子邮件地址.
I have Google it for past three days and i have tried in so many ways i didn't find solution for my issue. I have tried all scopes i didn't get email address in my access token.
String mScope = "oauth2:" + Scopes.PLUS_LOGIN + " " + Scopes.PLUS_ME;
String exchangeCode = GoogleAuthUtil.getToken(getApplicationContext(), Plus.AccountApi.getAccountName(mGoogleApiClient), mScope);
我在这里获取访问令牌,而不是我的令牌中的电子邮件地址
Here im getting access token and not email address in my token
String exchangeCode = GoogleAuthUtil.getToken(
SigninScreen.this,
Plus.AccountApi.getAccountName(mGoogleApiClient) + "",
"oauth2:"
+ Scopes.PLUS_ME + " "
+ "https://www.googleapis.com/auth/plus.login" + " "
+ "https://www.googleapis.com/auth/plus.me" + " "
+ "https://www.googleapis.com//auth/plus.profile.emails.read" + " "
+ "https://www.googleapis.com/auth/userinfo.profile");
在这里我收到这样的错误
here im getting error like this
com.google.android.gms.auth.UserRecoverableAuthException: NeedPermission
通过这种方式我也尝试了
by this way also i tried
accessToken = GoogleAuthUtil.getToken(
MainActivity.this,
Plus.AccountApi.getAccountName(mGoogleApiClient) + "",
"oauth2:"
+ Scopes.PROFILE + " "
+ "https://www.googleapis.com/auth/plus.login" + " "
+ "https://www.googleapis.com/auth/plus.profile.emails.read");
使用此方法出现错误
Client error response [url] https://www.googleapis.com/plus/v1/people/me?prettyPrint=false [status code] 403 [reason phrase] Forbidden
有人可以告诉我我做错了什么吗?我需要从Google Plus获取访问令牌,并将该令牌传递给我的网络服务并获取详细信息.
Can anyone tell me what am I doing wrong? I need to get the access token from Google Plus and pass the token to my webservice and get the details.
非常感谢.
推荐答案
最后三天后,我得到了解决方案.
Finally i got a solution after 3 days.
我更改了范围.现在,它的工作正常.我甚至可以从访问令牌中获取所有详细信息,甚至是电子邮件ID.
i have changed the scope. now its working fine. i can able get all details even email id from access token.
protected String doInBackground(String... args) {
String token = null;
String scope = "oauth2:" + Scopes.PLUS_LOGIN + " " + "https://www.googleapis.com/auth/userinfo.email" + " https://www.googleapis.com/auth/plus.profile.agerange.read";
try {
token = GoogleAuthUtil.getToken(
SigninScreen.this,
Plus.AccountApi.getAccountName(mGoogleApiClient),
scope);
System.out.println("OKAY!"+token);
} catch (IOException transientEx) {
// Network or server error, try later
Log.e(TAG, transientEx.toString());
} catch (UserRecoverableAuthException e) {
// Recover (with e.getIntent())
Log.e(TAG, e.toString());
Intent recover = e.getIntent();
startActivityForResult(recover, 125);
} 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;
这篇关于Google Plus使用访问令牌进行整合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!