小编cer*_*ina的帖子

Rails Google Client API - 无法为访问令牌交换刷新令牌

在我的机器上遇到一些SSL问题之后,我仍然试图通过Google Ruby Client API访问用户的Blogger帐户.我正在使用以下内容:

  • Rails 3.2.3
  • Ruby 1.9.3
  • oauth2(0.8.0)
  • omn​​iauth(1.1.1)
  • omn​​iauth-google-oauth2(0.1.13)
  • google-api-client(0.4.6)

我可以在身份验证时通过Google API成功验证用户身份并访问他们的博客.当用户登录时,我会存储access_tokenrefresh_token从Google收到.一切都很好,直到access_token过期.我正在尝试构建交换refresh_token新功能的功能access_token,但不断遇到问题.以客户端文档为例,这是我正在使用的代码:

  client = Google::APIClient.new
  token_pair = auth.oauth_token   # access_token and refresh_token received during authentication

  # Load the access token if it's available
  if token_pair  
    client.authorization.update_token!(token_pair.to_hash)
  end            

  # Update access token if expired
  if client.authorization.refresh_token && client.authorization.expired?
    client.authorization.fetch_access_token!
  end

  blogger = client.discovered_api('blogger', 'v3')
  result = client.execute(
      api_method: blogger.blogs.list_by_user,
      parameters: {'userId' => "self", 'fields' => …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails access-token oauth-2.0 omniauth google-api-client

15
推荐指数
2
解决办法
7802
查看次数