Authorization issue with cron crawler inserting data into Google spreadsheet using Google API in Ruby

我是研究僧i 提交于 2019-12-02 10:03:11
ZHH

Solved thanks to Ruby google_drive gem oAuth2 saving

I needed to get a refresh token and make my code use it like below.

CLIENT_ID = '!!!'
CLIENT_SECRET = '!!!'
OAUTH_SCOPE = 'https://www.googleapis.com/auth/drive'
REDIRECT_URI = 'urn:ietf:wg:oauth:2.0:oob'
REFRESH_TOKEN = '!!!'

client = Google::APIClient.new
client.authorization.client_id = CLIENT_ID
client.authorization.client_secret = CLIENT_SECRET
client.authorization.scope = OAUTH_SCOPE
client.authorization.redirect_uri = REDIRECT_URI
client.authorization.refresh_token = REFRESH_TOKEN
client.authorization.refresh! 

access_token = client.authorization.access_token
session = GoogleDrive.login_with_oauth(access_token)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!