重定向到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,access_token:client.authorization.access_token,refresh_token:client.authorization.refresh_token,register_id:userID,cloud_name:'drive')问题是,之前具有值的client.authorization.refresh_token现在正在返回空值,所以它是被作为NULL插入到DB中。这会在access_token过期时影响上传/刷新/下载。
我该做什么或者我做错了什么?
感谢。 解决方案
我遇到类似问题(从谷歌API获取刷新令牌)。我想如果你使用: prompt ='select_account consent'
然后强制一个新的批准屏幕上显示新的refresh_token。
noreferrer> developers.google/identity/protocols/OAuth2UserAgentSo I have a web app with ruby on rails that connects to google drive's API. Up until now, it used to receive the refresh token, since one of the paramenters I was using was offline. But recently it stopped getting it. The url that is being sent is this:
Redirected to accounts.google/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=localhost:3000/oauth2callbackdrive&response_type=code&scope=www.googleapis/auth/drive%20www.googleapis/auth/userinfo.emailThe code that is redirecting to the URI has this:
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_sOn the callback function I have this:
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!And on the same function I insert into the database:
CloudAccount.create(username: username,access_token:client.authorization.access_token, refresh_token:client.authorization.refresh_token,register_id:userID,cloud_name:'drive')Problem is, the client.authorization.refresh_token, which had a value before, now is returning empty and so it's being inserted into the DB as NULL. Which affects uploads/refresh/downloads when the access_token expires.
What can I do or what am I doing wrong?
Thanks.
解决方案I was having a similar issue (Getting a refresh token from google api). I think if you use: prompt='select_account consent'
then that forces a new approval screen and you get a new refresh_token.
Reference: developers.google/identity/protocols/OAuth2UserAgent
更多推荐
停止从谷歌的API获取刷新令牌
发布评论