簡體   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