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
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit
https://groups.google.com/d/msgid/adwords-api/693b6970-6fed-4598-9f89-dd37fe5df6c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.