ruby-on-rails - 使用有效的 access_token 时缺少 token 端点 URI

标签 ruby-on-rails oauth-2.0 google-api

突然间(可能是 gem 更新?)调用 Google api 停止工作。
我已经能够检索 gmail 线程,但不再。

到目前为止我所拥有的:

我能够检索刷新 token 以进行离线访问。所以我存储了刷新和访问 token 。伟大的。

现在我想检索个人资料信息。这就是我所做的(请注意,这曾经工作得很好!)

我将在下面的每一行之后添加一个 puts 来向你展示我们得到了什么......

module AuthHelper
  require 'google/api_client/client_secrets'
  ...
  client = Signet::OAuth2::Client.new(access_token: user.gmail_access_token)
  service = Google::Apis::GmailV1::GmailService.new
  service.authorization = client
  service.get_user_profile('me') # retrieve threads
  ...
end

让我打印我得到的回复:
CLIENT : --- !ruby/object:Signet::OAuth2::Client
authorization_uri: 
token_credential_uri: 
client_id: 
client_secret: 
code: 
expires_at: 
expires_in: 
issued_at: 
issuer: 
password: 
principal: 
redirect_uri: 
scope: 
state: 
username: 
expiry: 60
extension_parameters: {}
additional_parameters: {}
access_token: ya29.Ci8QA3K_mLh1vB_55bSnGVB66yLwzkxClM8yCI5qmmZo6n0JzjVNA7Q6EAOm3qQeGw

SERVICE : --- !ruby/object:Google::Apis::GmailV1::GmailService
root_url: https://www.googleapis.com/
base_path: gmail/v1/users/
upload_path: upload/gmail/v1/users/
batch_path: batch
client_options: !ruby/struct:Google::Apis::ClientOptions
  application_name: unknown
  application_version: 0.0.0
  proxy_url: 
  use_net_http: false
request_options: !ruby/struct:Google::Apis::RequestOptions
  authorization: 
  retries: 0
  header: 
  timeout_sec: 
  open_timeout_sec: 20

SERVICE.authorization : --- !ruby/object:Signet::OAuth2::Client
authorization_uri: 
token_credential_uri: 
client_id: 
client_secret: 
code: 
expires_at: 
expires_in: 
issued_at: 
issuer: 
password: 
principal: 
redirect_uri: 
scope: 
state: 
username: 
expiry: 60
extension_parameters: {}
additional_parameters: {}
access_token: ya29.Ci8QA3K_mLh1vB_55bSnGVB66yLwzkxClM8yCI5qmmZo6n0JzjVNA7Q6EAOm3qQeGw
{"message":"Sending HTTP get https://www.googleapis.com/gmail/v1/users/me/profile?","@timestamp":"2016-06-28T19:52:38.974-07:00","@version":"1","severity":"DEBUG","host":"ben.local"}
{"message":"Caught error Missing token endpoint URI.","@timestamp":"2016-06-28T19:52:38.976-07:00","@version":"1","severity":"DEBUG","host":"ben.local"}
{"message":"Error - #\u003cArgumentError: Missing token endpoint URI.\u003e\n","@timestamp":"2016-06-28T19:52:38.977-07:00","@version":"1","severity":"DEBUG","host":"ben.local"}
GOT EXCPETION: Missing token endpoint URI.

我不应该看到这个:“缺少 token 端点 URI”。当您使用 access_token 时,它应该处理授权,对吗?正如我所说,这不是以前的问题。

虽然我认为不需要,但我添加了端点 URI ' https://accounts.google.com/o/oauth2/auth ' 来自 clients_secret.json 并获得授权失败。

我错过了什么? :)

最佳答案

一旦你从他们的所有在线教程中真正获得了访问 token ,谷​​歌文档就删去了应该解释如何访问他们的 api 的部分!这里:

  • https://github.com/google/google-api-ruby-client
  • 停止解释如何使用此评论进行身份验证:“drive.authorization = ... # 请参阅 Googleauth 或 Signet 库”所以我们将前往 Signet,因为 Googleauth 是神秘的。
  • https://github.com/google/signet
  • 指导您如何获取访问 token ,然后停止解释如何处理它。
  • https://developers.google.com/identity/protocols/OAuth2WebServer#offline
  • 谷歌的 API 文档,向您展示了如何获取访问 token ,甚至是带有刷新的离线访问(我有),然后没有
    关于如何处理访问 token 的说明。

  • 我终于在这里找到了答案:https://github.com/google/google-api-ruby-client/issues/296

    基本上为访问 token 创建一个新类(我将它添加到我的 lib 文件夹中)并按照上面链接中描述的其余部分进行操作。仅将 .authenticate 替换为 .authorize,我想这是一个错误。希望这可以帮助某人。

    关于ruby-on-rails - 使用有效的 access_token 时缺少 token 端点 URI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38089763/

    相关文章:

    ruby-on-rails - 编辑 :How to send payments to users every month?

    php - Symfony2 OAuth2 提供程序错误 UserRepository

    coldfusion - 谷歌 oauth token 给出 405 错误

    php - Google API 查询获取访问范围?

    ruby-on-rails - Ruby 数组到 JSON 和 Rails JSON 渲染

    ruby-on-rails - 使用 Paperclip 将数千张图像上传到 S3

    ruby-on-rails - 允许在字符串列上使用 nil 值,但在 Rails 迁移中不允许使用空字符串

    python & smtplib : Is sending mail via gmail using oauth2 possible?

    java - 删除范围不起作用 - Google Sheets API - Swift

    google-apps-script - 在没有随机 Utilities.sleep 的情况下处理 UrlFetch 速率限制的正确方法?