gpt4 book ai didi

ruby - 谷歌 Adwords API 错误 : invalid grant

转载 作者:太空宇宙 更新时间:2023-11-03 16:00:20 26 4
gpt4 key购买 nike

我在尝试使用服务帐户和 JWT 与 Ruby API library 对 Adwords API 进行身份验证时收到此错误.

我正在复制 example provided , 但它似乎不起作用。

/home/michael/.rvm/gems/ruby-2.1.2/gems/signet-0.5.1/lib/signet/oauth_2/client.rb:941:in `fetch_access_token':授权失败。服务器消息:(Signet::AuthorizationError){ “错误”:“无效授权”

adwords_api.yml

---
# This is an example configuration file for the AdWords API client library.
# Please fill in the required fields, and copy it over to your home directory.
:authentication:
# Authentication method, methods currently supported: OAUTH2, OAUTH2_JWT.
:method: OAUTH2_JWT


# Auth parameters for OAUTH2_JWT method. See:
# https://developers.google.com/accounts/docs/OAuth2ServiceAccount
:oauth2_issuer: 43242...apps.googleusercontent.com
:oauth2_secret: 'notasecret'
# You can provide path to a file with 'oauth2_keyfile' or the key itself with
# 'oauth2_key' option.
:oauth2_keyfile: /home/.../google-api-key.p12
# To impersonate a user set prn to an email address.
:oauth2_prn: my@email.com

# Other parameters.
:developer_token: ua...w
:client_customer_id: 123-123-1234
:user_agent: test-agent
:service:
# Only production environment is available now, see: http://goo.gl/Plu3o
:environment: PRODUCTION
:connection:
# Enable to request all responses to be compressed.
:enable_gzip: false
# If your proxy connection requires authentication, make sure to include it in
# the URL, e.g.: http://user:password@proxy_hostname:8080
# :proxy: INSERT_PROXY_HERE
:library:
:log_level: INFO

测试.rb

#!/usr/bin/env ruby

require 'adwords_api'

def use_oauth2_jwt()
adwords = AdwordsApi::Api.new

adwords.authorize()

campaign_srv = adwords.service(:CampaignService, API_VERSION)

selector = {
:fields => ['Id', 'Name', 'Status'],
:ordering => [
{:field => 'Name', :sort_order => 'ASCENDING'}
]
}

response = campaign_srv.get(selector)
if response and response[:entries]
campaigns = response[:entries]
campaigns.each do |campaign|
puts "Campaign ID %d, name '%s' and status '%s'" %
[campaign[:id], campaign[:name], campaign[:status]]
end
else
puts 'No campaigns were found.'
end
end

if __FILE__ == $0
API_VERSION = :v201409

begin
use_oauth2_jwt()

# HTTP errors.
rescue AdsCommon::Errors::HttpError => e
puts "HTTP Error: %s" % e

# API errors.
rescue AdwordsApi::Errors::ApiException => e
puts "Message: %s" % e.message
puts 'Errors:'
e.errors.each_with_index do |error, index|
puts "\tError [%d]:" % (index + 1)
error.each do |field, value|
puts "\t\t%s: %s" % [field, value]
end
end
end
end

最佳答案

这很难给出明确的答案,因为它是基于授权的,因此错误消息是美化的“未授权”消息。

我真正能做的就是建议一些检查事项(承认您可能已经检查过这些):

  • 您的开发人员 token 肯定显示为“已批准”? (您可以在客户中心查看 - 通过设置 cog 然后是帐户然后是 adwords api 中心)
  • 您已通过 Google Developer Console 注册申请
  • 您(或您尝试访问的帐户的所有者)已授权您的申请 - 可能是通过关注 this guide并且肯定在某个时刻看到了这些东西之一:

Google Auth Screen

如果您已经检查了所有这些,那么我唯一可以建议的是发帖到 official forum他们往往会提供帮助并且经常将授权问题“离线”以查看实际的 soap 请求等。(我发现这比尝试通过 AdWords 的“支持”级别要快得多和容易得多)

祝你好运!

关于ruby - 谷歌 Adwords API 错误 : invalid grant,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27066634/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com