Google Adwords API错误:授予无效

mz3

我收到此错误,尝试使用服务帐户和带有Ruby API库的JWT对Adwords API进行身份验证

我正在复制提供示例,但似乎无法正常工作。

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

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: [email protected]

  # 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

test.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
mz3

经过几个小时的摆弄,我终于通过将oauth2_prn设置为MCC和Google Apps for Business帐户上的主要电子邮件,使其正常工作。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Google Adwords API中的响应顺序

来自分类Dev

Google Adwords API网站链接扩展报告

来自分类Dev

通过api的Google AdWords帐户权限

来自分类Dev

Google Adwords API-刷新令牌-python

来自分类Dev

api google adwords如何获取广告报告?

来自分类Dev

使用 Google Adwords api 时出错

来自分类Dev

使用Google Adwords API时出现解组错误

来自分类Dev

RCurl用于Google Adwords

来自分类Dev

关于Google AdWords转换

来自分类Dev

RCurl用于Google Adwords

来自分类Dev

Google AdWords脱销脚本

来自分类Dev

关于Google AdWords转换

来自分类Dev

Google Adwords PHP SDK userAgent验证错误(V201406)

来自分类Dev

如何从Google Analytics(分析)API获取Adwords广告系列数据?

来自分类Dev

在Google Apps脚本中使用Adwords API(MccApp)

来自分类Dev

带有Grant_type密码的Google AdWords API访问

来自分类Dev

Google AdWords API调用中的操作数

来自分类Dev

Google AdWords API 中是否有 DEVICE_PERFORMANCE_REPORT

来自分类Dev

通过 Google Ads API 运行或安排 Adwords 脚本

来自分类Dev

AdWords转化跟踪无效

来自分类Dev

AdWords API Cookie过期错误

来自分类Dev

Google AdWords和Laravel 5.2

来自分类Dev

如何获得Google AdWords API中关键字的当前每次点击费用出价?

来自分类Dev

无法使用Google Adwords API将谓词添加到选择器

来自分类Dev

Google Adwords API异常:调用公共抽象SimpleMutateJob时有多个SoapHeader

来自分类Dev

如何使用Google AdWords API获取所有广告系列的详细信息?

来自分类Dev

PHP Google Adwords API v201406:获得总点击次数,总展示次数(按CampaignId)

来自分类Dev

如何通过Google Adwords API将自动标记设置为true

来自分类Dev

如何不将OAuth2与Google API结合使用(尤其是adwords)

Related 相关文章

热门标签

归档