Hello,

We have scripts on our GoogleAds account that periodically extract campaign 
report data from the platform and saves them in our BigQuery database on 
Google Cloud.

The script begins by looping over all our accounts and then fetches the 
reports of the campaigns under each account:

var excluded_account_ids = ['xxx', 'xxx', 'xxx'];
  
  // Retrieve all child accounts.
  var accountIterator = AdsManagerApp.accounts().get();

  // this array will hold all of the insert 
  var values_array = [];

  // Iterate through the account list.
  while (accountIterator.hasNext()) {
    var account = accountIterator.next();

    // Making sure that the account ID isn't among the excluded ones
    if(excluded_account_ids.indexOf(account.getCustomerId()) < 0) {     
      Logger.log(account.getCustomerId())
      AdsManagerApp.select(account);

      var report = AdsApp.report(
        'SELECT Date, CampaignId, CampaignName, AdGroupId, AdGroupName, 
Device, DayOfWeek, Impressions, Clicks, Ctr, VideoViews, VideoViewRate, 
VideoQuartile100Rate, VideoQuartile25Rate, VideoQuartile50Rate, 
VideoQuartile75Rate, Conversions, Cost, ActiveViewMeasurability, 
ActiveViewViewability, ActiveViewImpressions, 
ActiveViewMeasurableImpressions, ViewThroughConversions ' +
        'FROM   ADGROUP_PERFORMANCE_REPORT ' +
        'DURING ' + current_date[0] + ',' + current_date[0], {
          includeZeroImpressions: false,
          returnMoneyInMicros: true
        });

      var rows = report.rows();

When we print the customer IDs fetched by the above script, we get 207 
different customer IDs.

However, when we try to do the same in our python scripts through APIs, 
we're only able to get the IDs of the most top-level accounts (only 3 IDs 
and one isn't enabled) and when we proceed with fetching the campaigns 
under these top-level accounts, the search always comes back empty. A 
snippet of the python script is attached and our main account's customer ID 
is 325-177-1939.

Can you please advise on what we're doing wrong in the python script?

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads 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 and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/b68e1c68-8716-4a09-9842-eef128907b4an%40googlegroups.com.
client = GoogleAdsClient.load_from_dict(credentials)

    customer_service = client.get_service("CustomerService")

    accessible_customers = customer_service.list_accessible_customers()

    customer_ids = []

    for resource_name in accessible_customers.resource_names:
        customer_id = customer_service.parse_customer_path(resource_name)['customer_id']
        customer_ids.append(customer_id)

    ga_service = client.get_service("GoogleAdsService")

    query = """
            SELECT
              campaign.id,
              campaign.name
            FROM campaign
            ORDER BY campaign.id"""

    for customer_id in customer_ids:
        try:
            stream = ga_service.search_stream(customer_id=customer_id, query=query)

            for batch in stream:
                for row in batch.results:
                    print(
                        f"Campaign with ID {row.campaign.id} and name "
                        f'"{row.campaign.name}" was found.'
                    )
        except:
            print("an error occurred")
            print(customer_id)
  • Un... Hadil Charafeddine
    • ... 'Google Ads API Forum Advisor' via AdWords API and Google Ads API Forum
      • ... Hadil Charafeddine
        • ... 'Google Ads API Forum Advisor' via AdWords API and Google Ads API Forum

Reply via email to