刷新 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/