Google api Google授权代码流-无刷新令牌
我正在使用GoogleAPI为离线访问获取访问和刷新令牌,但是,刷新令牌始终为空 授权代码来自客户端,因此我将其与服务器上的令牌交换:Google api Google授权代码流-无刷新令牌,google-api,google-oauth,google-api-java-client,Google Api,Google Oauth,Google Api Java Client,我正在使用GoogleAPI为离线访问获取访问和刷新令牌,但是,刷新令牌始终为空 授权代码来自客户端,因此我将其与服务器上的令牌交换: GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder( HTTP_TRANSPORT, JSON_FACTORY, clientId, clientSecret, scopes) .setAccessType("offline"
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT,
JSON_FACTORY,
clientId,
clientSecret,
scopes)
.setAccessType("offline")
.build();
GoogleTokenResponse response = flow
.newTokenRequest(authorizationCode)
.setRedirectUri(redirectUri)
.execute();
// response has access_token and id_token. don't see any refresh token here
return flow.createAndStoreCredential(response, null);
// this returns Credential with refreshToken = null
客户端代码:
$(document).ready(function() {
gapi.load('auth2', function() {
auth2 = gapi.auth2.init({
client_id: '<my client id>',
// Scopes to request in addition to 'profile' and 'email'
scope: 'https://www.google.com/m8/feeds https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/drive.appfolder'
});
});
$('#signinButton').click(function() {
auth2.grantOfflineAccess({'redirect_uri': 'postmessage'}).then(onSignIn);
});
});
// the onSignIn function sends the one time code (i.e. authResult['code']) to the server
$(文档).ready(函数(){
load('auth2',function(){
auth2=gapi.auth2.init({
客户端id:“”,
//除了“配置文件”和“电子邮件”之外,还可以请求范围
范围:'https://www.google.com/m8/feeds https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/drive.appfolder'
});
});
$(“#登录按钮”)。单击(函数(){
auth2.grantoflineaccess({'redirect_uri':'postmessage'});
});
});
//onSignIn函数将一次性代码(即authResult['code'])发送到服务器
我做错什么了吗
我看到了这个问题:但它并没有真正回答我的问题,我也不知道刷新令牌只是在用户第一次登录时创建的
编辑:
我认为这实际上是客户端的问题,因为“同意”窗口不要求脱机访问。将根据此处新问题的结果更新此问题: