Ruby on rails 使用服务帐户测试Adwords Api
我使用gem为离线转换feedservice使用adwords api。 代码看起来不错:Ruby on rails 使用服务帐户测试Adwords Api,ruby-on-rails,testing,google-ads-api,service-accounts,Ruby On Rails,Testing,Google Ads Api,Service Accounts,我使用gem为离线转换feedservice使用adwords api。 代码看起来不错: module AdwordsHelper def mark_conversion_in_ads(customer) begin config_filename = File.join(Rails.root, 'config', 'adwords_api.yml') adwords = AdwordsApi::Api.new(config_filename) conversion_feed_sr
module AdwordsHelper
def mark_conversion_in_ads(customer)
begin
config_filename = File.join(Rails.root, 'config', 'adwords_api.yml')
adwords = AdwordsApi::Api.new(config_filename)
conversion_feed_srv =
adwords.service(:OfflineConversionFeedService, :v201702)
conversion_time = Time.new.strftime("%Y%m%d %H%M%S")
conversion_value = '100'.to_f
feed = {
:google_click_id => customer.gclid,
:conversion_name => 'LeadCreatedAll',
:conversion_time => conversion_time,
:conversion_value => conversion_value,
:conversion_currency_code => 'GBP'
}
return_feeds = conversion_feed_srv.mutate([
{:operator => 'ADD', :operand => feed}])
return_feeds[:value].each do |return_feed|
puts ("Uploaded offline conversion value %.2f for Google Click ID '%s', " +
'to %s') % [return_feed[:conversion_value],
return_feed[:google_click_id],
return_feed[:conversion_name]]
end
rescue AdwordsApi::Errors::ApiException => e
puts e.backtrace
Logger.log_message("Exception occurred: %s\n%s" % [e.to_s, e.message])
rescue AdsCommon::Errors::OAuth2VerificationRequired => e
puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
"OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
"to retrieve and store OAuth2 tokens."
puts "See this wiki page for more details:\n\n " +
'https://github.com/googleads/google-api-ads-ruby/wiki/OAuth2'
# 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
end
我的adwords_api.yml文件是:
---
:authentication:
:method: OAUTH2_SERVICE_ACCOUNT
:oauth2_keyfile: "/path/to_prod_manager_server_account_file/jsonkey.json"
:developer_token: test_level_developer_token_of_production_manager_account
:client_customer_id: client_customer_id_of_test_manager_account
:oauth2_token:
:access_token: access_token_generated_setup_oauth.rb
:issued_at: 2017-03-16 13:12:25.005441000 +05:30
:expires_in: 3600
:id_token:
:service:
:environment: PRODUCTION
:connection:
:enable_gzip: false
:library:
:log_level: INFO
我已尝试测试此设置很长时间,但出现以下错误:
发生异常:[AuthenticationError.NOT_ADS_USER@;触发器:“”]
[AuthenticationError.NOT_ADS_USER@;触发器:“”]
我尝试了很多链接:
有人能提供关于如何测试它的确切步骤吗。
为了进一步澄清,我在adwords中输入了TestAccountDeveloper关键字
使用adwords api v201702
我尝试使用的api是
为了澄清,您是否在G套件域中使用此选项?如果是这样,您可能需要将整个域的访问权委托给服务帐户,并指定要模拟的用户。@Dorian否,我没有使用G套件域。但我找到了解决办法。我放弃了服务帐户,开始使用已安装的应用程序流,这很有魅力。