安卓 : Google Sign-in Invalid token

标签 android token google-signin

我通过 android 中的谷歌登录收到的 token 出现错误:

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

我还注意到,与我在 iOS 中获得的 token 相比,我的 token 看起来有点短:

ya29.4AFYx2XNZ1sdfdzhWo-of-fSpsDPjgmATx-J82mCjqZJXglwj8VOvedpY_YXJgEVIWe

我得到这样的 token :

 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);
        }
}

知道可能会发生什么,或者如何更深入地调试问题吗?

最佳答案

好的,所以我找到了答案,作用域必须这样写:

String scopes = "oauth2:"
                + Scopes.PLUS_LOGIN
                + " "
                + Scopes.PROFILE;

Android 和 iOS 端点不同

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

关于安卓 : Google Sign-in Invalid token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32329229/

相关文章:

android - 在 Activity 可见之前隐藏键盘

android - 在另一个 Activity 中检索存储在共享首选项中的值

php - Zend Framework 2 电子邮件 token 验证

angular - 为 AoT 编译标记化

login - Google 登录网站错误 : Permission denied to generate login hint for target domain

c# - 如何在 Android 中禁用布局的所有触摸

c++ - 编译错误: solution.c:20:5: error: expected identifier or ‘(’ before ‘{’ token {

java - Google 登录突然无法使用

android - 在android应用程序中集成outlook 365登录

android - Android 中的照片分享 Intent