Testing Adwords Api with Service Account

225 views
Skip to first unread message

Amrata Baghel

unread,
Mar 16, 2017, 4:21:56 AM3/16/17
to AdWords API Forum
I am using https://github.com/googleads/google-api-ads-ruby/ gem for using adwords api for OfflineConversionFeedService. Code looks alright:

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

My adwords_api.yml file is:

---
:authentication:
:method: OAUTH2_SERVICE_ACCOUNT
:oauth2_keyfile: "/path/to_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

I have been trying to test this setup for a long time and am getting this error: Exception occurred: [AuthenticationError.NOT_ADS_USER @ ; trigger:''] [AuthenticationError.NOT_ADS_USER @ ; trigger:'']

I have tried a lot of links: managing test accounts

Can someone please provide exact steps on how to test it out. For some more clarification, I have Test Account developer key in adwords.

Using adwords api v201702 The api I am trying to use is OfflineConversion



Peter Oliquino

unread,
Mar 16, 2017, 4:56:12 AM3/16/17
to AdWords API Forum
Hi Amrata,

The NOT_ADS_USER error indicates that the email address used to generate your OAuth2 credentials are not associated with any AdWords accounts. The solution would be to login to the email account associated to you test MCC account and re-generate your OAuth2 credentials. Let me know if this helps.

Best regards,
Peter
AdWords API Team

Amrata Baghel

unread,
Mar 16, 2017, 8:11:17 AM3/16/17
to AdWords API Forum
HI Peter,

So glad you replied early. I am currently using Test Account. I have created a test manager account for adwords. This is the one I used to create the oauth2 service account credentials. I added the same credentials and the client customer id of the same test manager account. Still it fails. Lets say I have a production manager account PM1 on adwords and a test manager account(TM1) created using the PM1. As I mentioned, I want to use the Service Account credentials, so I log on as TM1...create the project on console.google.developer.com...create a service account...download json and use it for oauth2. For client customer id, I am providing the TM1 client customer id. It is still failing. 

Regards

Peter Oliquino

unread,
Mar 16, 2017, 11:59:28 PM3/16/17
to AdWords API Forum
Hi Amrata,

In this case, I would like to ask your confirmation if the email address you associated to your test MCC account was also the same email you used when generating the OAuth2 credentials? If you may have used the email login of your production MCC, then it could be the cause as to why you are experiencing this error.

If you have used the email associated to your test MCC and that you are still encountering the issue, could you provide the customer ID of your production MCC and the SOAP request and response generated when you used your test account? Please reply privately using Reply privately to author for the requested information.

Thanks and regads,
Peter
AdWords API Team
Reply all
Reply to author
Forward
0 new messages