javascript - 谷歌 api 刷新 token 返回 null 与 react-google-login

标签 javascript java google-api

刷新 token 始终为空,我浏览了文档并做了一些实验。但我无法获得 refreshToken 来更新访问 token 以供离线使用。

我正在使用 react-google-login 来获取我的离线 token 。我认为这是正确设置的。

以防万一这是设置:

    <GoogleLogin
        clientId="***"
        buttonText="Login"
        accessType="offline"
        responseType="code"
        scope={"https://www.googleapis.com/auth/calendar"}
        onSuccess={responseGoogle}
        onFailure={responseGoogle}
    />

但是当我使用授权码时,只返回一个有效期为 3600 秒的访问 token 。我可以使用 accessToken 来访问 api。但似乎没有提供刷新 token 。
    GoogleTokenResponse tokenResponse =
            new GoogleAuthorizationCodeTokenRequest(
                    new NetHttpTransport(),
                    JacksonFactory.getDefaultInstance(),
                    "https://www.googleapis.com/oauth2/v4/token",
                    clientSecrets.getDetails().getClientId(),
                    clientSecrets.getDetails().getClientSecret(),
                    AUTH_CODE,
                    REDIRECT_URL)
                    .execute();



    String refreshToken = tokenResponse.getRefreshToken();
    String accessToken = tokenResponse.getAccessToken();

任何线索有什么问题?

最佳答案

似乎它与 react-google-login 有关......所以我一直在看错误的东西。添加 approvalPrompt="force"prompt='consent'似乎修复它。

    <GoogleLogin
        clientId="***"
        buttonText="Login"
        accessType="offline"
        responseType="code"
        approvalPrompt="force"
        prompt='consent'
        scope={"https://www.googleapis.com/auth/calendar"}
        onSuccess={responseGoogle}
        onFailure={responseGoogle}
    />

关于javascript - 谷歌 api 刷新 token 返回 null 与 react-google-login,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53969774/

相关文章:

javascript - onclick事件不改变元素ID

javascript - 在 Canvas 上绘制 Div 的背景图片

javascript - Vue 多选显示始终在 Bootstrap 输入组后面

java - 丢失的套接字消息

javascript - 动态更改关键帧 CSS Firefox

java - 使用 jxpath 按特定属性查找数组中的元素

java - 如何在 api 调用中使用 token 对用户进行身份验证?

python - Google 是否允许其他人使用他们的 "Did you mean"API?

javascript - Google Api获取access_token请求返回invalid_request

google-api - 使用 Google Drive API 更新权限时出现 500 错误