突然间(可能是 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 的部分!这里:
关于如何处理访问 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/