停止从谷歌的API获取刷新令牌

所以我有一个带有ruby on rails的web应用程序连接到google drive的API。 到目前为止,它曾用于接收刷新令牌,因为我使用的其中一个参数是离线的。 但最近它停止了它。 正在发送的url是:

Redirected to https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=ID&options=%7B:access_type=%3E%22offline%22,%20:approval_prompt=%3E%22force%22%7D&redirect_uri=http://localhost:3000/oauth2callbackdrive&response_type=code&scope=https://www.googleapis.com/auth/drive%20https://www.googleapis.com/auth/userinfo.email 

重定向到URI的代码包含:

 client = Google::APIClient.new client.authorization.client_id = GOOGLE_CLIENT_ID client.authorization.client_secret = GOOGLE_CLIENT_SECRET client.authorization.scope = SCOPES client.authorization.redirect_uri = GOOGLE_CLIENT_REDIRECT_URI auth_url = client.authorization.authorization_uri(:options => {:access_type => :offline, :approval_prompt => :force}.to_s) redirect_to auth_url.to_s 

在回调函数上我有这个:

 client = Google::APIClient.new client.authorization.client_id = GOOGLE_CLIENT_ID client.authorization.client_secret = GOOGLE_CLIENT_SECRET client.authorization.scope = SCOPES client.authorization.redirect_uri = GOOGLE_CLIENT_REDIRECT_URI client.authorization.code = params['code'] client.authorization.fetch_access_token! 

在同一个函数中我插入数据库:

 CloudAccount.create(username: username,access_token:client.authorization.access_token, refresh_token:client.authorization.refresh_token,register_id:userID,cloud_name:'drive') 

问题是,之前有一个值的client.authorization.refresh_token现在返回空,因此它作为NULL插入到数据库中。 当access_token到期时,会影响上传/刷新/下载。

我能做什么或我做错了什么?

谢谢。

我遇到了类似的问题( 从谷歌API获取刷新令牌 )。 我想如果你使用: prompt='select_account consent'

然后强制一个新的批准屏幕,你得到一个新的refresh_token。

参考: https : //developers.google.com/identity/protocols/OAuth2UserAgent