Tag: 的Gmail的IMAP

Google OAuth访问令牌

OAuth和Google让我很困惑。 我花了很长时间才得到refresh_token来创建一个新的access_token。 然后找出refresh_token也过期了? 有什么意义!!! 我需要做的就是坚持使用有效的access_token与legato一起使用。 这是我手动输入终端以检索OAUTH代码的内容: client = OAuth2::Client.new(‘GA_CLIENT_ID’, ‘GA_SECRET_KEY’, { :authorize_url => ‘https://accounts.google.com/o/oauth2/auth’, :token_url => ‘https://accounts.google.com/o/oauth2/token’ }) client.auth_code.authorize_url({ :scope => ‘https://www.googleapis.com/auth/analytics.readonly’, :redirect_uri => ‘http://localhost’, :access_type => ‘offline’, :approval_prompt=> ‘force’ }) 然后我在我的浏览器中手动输入输出的URL。 我将返回的OAUTH代码导出为env变量并获取访问令牌: access_token = client.auth_code.get_token(ENV[‘GA_OAUTH_CODE’], :redirect_uri => ‘http://localhost’) 然后我可以访问access_token和refresh_token: begin api_client_obj = OAuth2::Client.new(ENV[‘GA_CLIENT_ID’], ENV[‘GA_SECRET_KEY’], {:site => ‘https://www.googleapis.com’}) api_access_token_obj = OAuth2::AccessToken.new(api_client_obj, ENV[‘GA_OAUTH_ACCESS_TOKEN’]) self.user = Legato::User.new(api_access_token_obj) […]