安卓谷歌签到令牌无效 [英] Android : Google Sign-in Invalid token

查看:300
本文介绍了安卓谷歌签到令牌无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从我通过谷歌标志android系统接收令牌的错误:

I am getting an error from the token I am receiving through google sign in android:

{错误:INVALID_TOKEN,ERROR_DESCRIPTION:无效值}

{ "error": "invalid_token", "error_description": "Invalid Value" }

我也注意到,我的令牌相比,一个我在iOS中越来越显得有点短:

I also noticed that my token looks a bit short compared to the one I am getting in 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;

和端点从不同的Andr​​oid到iOS

And the endpoint differs from android to iOS

'https://www.googleapis.com/oauth2/v1/tokeninfo?id_token='; //for iOS
'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token='; //for android

这篇关于安卓谷歌签到令牌无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆