繁体   English   中英

AuthenticationError.OAUTH_TOKEN_INVALID

[英]AuthenticationError.OAUTH_TOKEN_INVALID

我正在尝试通过Google的gem google-api-ads-ruby访问Google Adword的api。 我能够很好地进行oauth,并获得了访问令牌,刷新令牌和id_token。 当我尝试访问数据时,它给了我oauth令牌无效错误。 我检索了访问令牌并在此链接上输入了它,它返回了一个有效的结果。

https://www.googleapis.com/oauth2/v1/tokeninfo?access_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令牌仍然是无效错误?

如果问题仍然存在。

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

它有助于解决我的情况下的类似问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM