Unable to access a customer account for Ads data even with MCC access
I Have MCC access under which there are multiple accounts, however, I can only access 3 accounts out of them.
This is the structure of my YAML file.
This is the Error Log for the same.
Here is the snippet of the python code used
from google.ads.googleads.client import GoogleAdsClient from google.ads.googleads.errors import GoogleAdsException import pandas as pd from google.protobuf.json_format import MessageToJson import json import logging logging.basicConfig(level=logging.INFO, format='[%(asctime)s - %(levelname)s] %(message).5000s') logging.getLogger('google.ads.googleads.client').setLevel(logging.INFO) client = GoogleAdsClient.load_from_storage("/Users/abhishekkumar/Downloads/google_ads_2.yml") ga_service = client.get_service("GoogleAdsService") customer_id = "6376354833" query = f""" SELECT campaign.id, campaign.name, campaign.status, metrics.cost_micros, metrics.ctr, metrics.clicks, metrics.all_conversions, metrics.absolute_top_impression_percentage, metrics.impressions, metrics.search_impression_share, campaign.start_date, segments.date FROM campaign WHERE segments.date DURING LAST_7_DAYS """ # Issues a search request using streaming. response = ga_service.search(customer_id=customer_id, query=query) rows = [] for row in response: serialized_json = MessageToJson(row).replace('\n', '') serialized_json_dict = json.loads(serialized_json) df_row = pd.json_normalize(serialized_json_dict) rows.append(df_row) if len(rows) == 0: continue df = pd.concat(rows)
As we discussed in the support forum, the issue here is that the login-customer-id isn't being loaded from yaml, and is thus not being included in the request metadata.
You've already checked:
- That the
load_from_storagemethod is loading the yaml file you expect. - You're not modifying the
login_customer_idproperty on the GoogleAdsClient instance.
I'll try testing with a yaml that's structured like yours to see if there's an issue in the config module.
@CodesOfAnurag one other thought I had - can you confirm that the other necessary tokens are loaded onto the client instance? If you add the below lines to your script, you should be able to confirm that they match what's in your yaml file. And please don't post any of these token values here, just confirm directly that they match.
print(client.developer_token)
print(client.credentials.client_id)
print(client.credentials.client_secret)
print(client.credentials.refresh_token)
@BenRKarl I have added these print statements in my code, the values printed matches the yaml file
,
@BenRKarl I am not sure what happened exactly over here, I created a new app from scratch on Google Cloud Console to get the new set of credentials in YAML file. I am able to fetch data now.