Problem in authentication of client id of sub manager account.

58 views
Skip to first unread message

Nishant Rawat

unread,
Oct 19, 2016, 9:56:00 AM10/19/16
to AdWords API Forum
I have a google adword manager account with several client account and a sub-manager account which further have more client account.

1) The purpose of using api to get daily data of the campaigns running under different client ids.

The problem is that when i start using api, all the account which are not under sub-manager are working fine, but i start getting auth error on the account which are under sub-manager.

My Implementation:
1) I am saving the details of adwords api in database.

I am storing these values in database

   adwordDetails = [{method: 'OAuth2',oauth2_client_id: '69423171055-3jcp5htcfnl1xyxxxxxxxxxx8ddk.apps.googleusercontent.com', oauth2_client_secret:'bXQZQwfvlAJmqcVWxxxxxxx',developer_token: '2AEaikb-4S9v0xxxxxxxxxx', client_customer_id:'460-139-xxxx'},
{method: 'OAuth2',oauth2_client_id: '69423171055-3jcp5htcfnl1xyxxxxxxxxxx8ddk.apps.googleusercontent.com', oauth2_client_secret:'bXQZQwfvlAJmqcVWxxxxxxx',developer_token: '2AEaikb-4S9v0xxxxxxxxxx', client_customer_id:'424-681-xxxx'},
{method: 'OAuth2',oauth2_client_id: '69423171055-3jcp5htcfnl1xyxxxxxxxxxx8ddk.apps.googleusercontent.com', oauth2_client_secret:'bXQZQwfvlAJmqcVWxxxxxxx',developer_token: '2AEaikb-4S9v0xxxxxxxxxx', client_customer_id:'634-086-xxxxx'},
   {method: 'OAuth2',oauth2_client_id: '69423171055-3jcp5htcfnl1xyxxxxxxxxxx8ddk.apps.googleusercontent.com', oauth2_client_secret:'bXQZQwfvlAJmqcVWxxxxxxx',developer_token: '2AEaikb-4S9v0xxxxxxxxxx', client_customer_id:'805-521-xxxx'},
   {method: 'OAuth2',oauth2_client_id: '69423171055-3jcp5htcfnl1xyxxxxxxxxxx8ddk.apps.googleusercontent.com', oauth2_client_secret:'bXQZQwfvlAJmqcVWxxxxxxx',developer_token: '2AEaikb-4S9v0xxxxxxxxxx', client_customer_id:'131-908-xxxxxx'}
  
]

Here client id after 634-086-9549 belong to sub mcc.

      adword_configuration = DspAdwordsConfiguration.all  
      adword_configuration.each do |configuration|
        adwords = AdwordsApi::Api.new({
          :authentication => 
            { 
              :method => configuration.method,
              :oauth2_client_id => configuration.oauth2_client_id,
              :oauth2_client_secret => configuration.oauth2_client_secret,
              :developer_token => configuration.developer_token,
              #:client_customer_id => configuration.client_customer_id,
              :user_agent => 'ADCAMIE_ADWORD_REPORT',
              :oauth2_token =>{:access_token => configuration.access_token,
                           :refresh_token => configuration.refresh_token
                            }
                            
                },
          :service => {:environment => 'PRODUCTION'},
          :connection => {:enable_gzip => false},
          :library => {:log_level => 'INFO'}
      })
      adwords.config.set("authentication.client_customer_id", configuration.client_customer_id)
      #puts configuration.access_token
      token = adwords.authorize() do |auth_url|
        puts "Auth error, please navigate to URL:\n\t%s" % auth_url
        puts 'log in and type the verification code:'
        verification_code = gets.chomp
      end   
      if token
          hash = HashWithIndifferentAccess.new(token)
          referesh_token = hash['refresh_token']
          access_token = hash['access_token']
          developer_token = configuration.developer_token
          #puts hash['access_token']
          #issued_at = hash['issued_at']
          #expires_in = hash['expires_in']
          DspAdwordsConfiguration.where(:developer_token => developer_token).update_all("access_token = '#{access_token}', refresh_token = '#{referesh_token}' ")       
          #puts "new token saved"
      else
        raise AdsCommon::Errors::Error, "Can't save nil token"
      end
      report_utils = adwords.report_utils(get_api_version())
      report_definition = {
                  :selector => {
                    :fields => ['CampaignId','CampaignName','Clicks','Conversions','Impressions','Interactions','HourOfDay' ],
                   },
                :report_name => 'TODAY CAMPAIGN PERFORMANCE REPORT',
                  :report_type => 'CAMPAIGN_PERFORMANCE_REPORT',
                  :download_format => 'XML',
                  :date_range_type => 'TODAY',
                 }
         debugger        
        file_name = File.join(Rails.root, 'reports', 'report_automation.xml')
        adwords.skip_report_header = false
        adwords.skip_column_header = false
        adwords.skip_report_summary = false
        adwords.include_zero_impressions = false
        report_utils.download_report_as_file(report_definition, file_name)

this is the code i am using

Shwetha Vastrad (AdWords API Team)

unread,
Oct 19, 2016, 12:44:18 PM10/19/16
to AdWords API Forum
Hi Nishant,

Could you provide the details of the error you receive when trying to download reports for client accounts under the sub-manager account? Could you also confirm that you are using the OAuth credentials associated with the main manager account to download reports for all the accounts? If you can enable logging and provide the logs generated when the error occurs, it'll help me in investigating the issue. Please use Reply privately to author when responding. 

Thanks,
Shwetha, AdWords API Team. 

Nishant Rawat

unread,
Oct 21, 2016, 4:44:43 PM10/21/16
to AdWords API Forum
Waiting for reply

Shwetha Vastrad (AdWords API Team)

unread,
Oct 21, 2016, 4:51:08 PM10/21/16
to adwor...@googlegroups.com
Hi Nishant,

I sent an e-mail asking for more information. Looks like you did not receive the message. Here it is:

Does your program refresh expired access tokens? An access token has an expiration time (based on the expires_in value) after which the token is no longer valid. The client libraries are programmed to automatically refresh expired access tokens by default. There is currently a limit of 50 refresh tokens per user account per client. If the limit is reached, creating a new token automatically invalidates the oldest token without warning. 

Have you tried using the examples available in the AdWords API Ruby client library? Could you enable logging and provide the SOAP request and response logs generated? Please use Reply privately to author when sending the logs.

Reply all
Reply to author
Forward
0 new messages