AuthenticationError.OAUTH_TOKEN_INVALID

问题描述 投票:0回答:1

我试图通过google的gem google-api-ads-ruby访问Google Adword的API。我能够完美地完成oauth并抓住访问令牌,刷新令牌和id_token。当我尝试访问数据时,它会给我oauth令牌无效错误。我检索了我的访问令牌并在此链接上输入了它,它返回了一个有效的结果。

https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=[TOKEN]

下面的代码是我尝试访问报表定义服务的方式。

config = {
  :authentication => {
      :method => 'OAuth2',
      :oauth2_client_id => @plugin.oauth_client_id,
      :oauth2_client_secret => @plugin.oauth_client_secret,
      :developer_token => @plugin.developer_token,
      :client_customer_id => @plugin.client_customer_id,
      :oauth2_token => {"access_token"=>ACCESSTOKEN,
                       "refresh_token"=>REFRESHTOKEN,
                       "issued_at"=>"2017-09-18T16:36:55.973-04:00",
                       "expires_in"=>3600,
                       "id_token"=>IDTOKEN,
                       :user_agent => 'Example'
                      },
  :service => {
    :environment => 'PRODUCTION'
  }
}
api = AdwordsApi::Api.new(config)
report_def_srv = api.service(:ReportDefinitionService, :v201708)
report_type = "ACCOUNT_PERFORMANCE_REPORT"

下面的代码会导致错误

fields = report_def_srv.get_report_fields(report_type)

为什么我还没有得到oauth令牌无效的错误呢?

ruby-on-rails ruby oauth google-adwords
1个回答
0
投票

如果问题仍然存在..

尝试用"expires_in"=>3600替换"expires_at"=>"2017-09-18T17:36:55.973-04:00"字段

在我的案例中,它有助于解决类似的问题。

© www.soinside.com 2019 - 2024. All rights reserved.