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.
1) I am saving the details of adwords api in database.
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)