[英]Android : Google Sign-in Invalid token
I am getting an error from the token I am receiving through google sign in android: 我从通过谷歌登录android收到的令牌收到错误:
{ "error": "invalid_token", "error_description": "Invalid Value" }
{“error”:“invalid_token”,“error_description”:“无效值”}
I also noticed that my token looks a bit short compared to the one I am getting in iOS: 我还注意到,与我在iOS中获得的令牌相比,我的令牌看起来有点短:
ya29.4AFYx2XNZ1sdfdzhWo-of-fSpsDPjgmATx-J82mCjqZJXglwj8VOvedpY_YXJgEVIWe
I am getting the token like this: 我得到这样的令牌:
private class RetrieveTokenTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
String accountName = params[0];
String scopes = "oauth2:profile email";
String token = null;
try {
token = GoogleAuthUtil.getToken(getActivity().getApplicationContext(), accountName, scopes);
} catch (IOException e) {
Log.e(TAG, e.getMessage());
} catch (UserRecoverableAuthException e) {
//startActivityForResult(e.getIntent(), REQ_SIGN_IN_REQUIRED);
} catch (GoogleAuthException e) {
Log.e(TAG, e.getMessage());
}
return token;
}
@Override
protected void onPostExecute(String token) {
super.onPostExecute(token);
Log.i("Token Value: ", token);
}
}
Any idea what might be happening, or how to debug more in depth the problem? 知道可能会发生什么,或者如何更深入地调试问题?
Ok so I found the answer, the scopes must be written like this: 好的,我找到了答案,范围必须写成:
String scopes = "oauth2:"
+ Scopes.PLUS_LOGIN
+ " "
+ Scopes.PROFILE;
And the endpoint differs from android to iOS 端点不同于Android到iOS
'https://www.googleapis.com/oauth2/v1/tokeninfo?id_token='; //for iOS
'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token='; //for android
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.