How to solve customer_id error in google ads api(python)
Try running the example get_campaign.py in the google ads api. The code was entered as follows
import argparse import sys from google.ads.google_ads.client import GoogleAdsClient from google.ads.google_ads.errors import GoogleAdsException def main(client, customer_id): ga_service = client.get_service("GoogleAdsService", version="v6") query = """ SELECT campaign.id, campaign.name FROM campaign ORDER BY campaign.id""" # Issues a search request using streaming. response = ga_service.search_stream(customer_id, query=query) try: for batch in response: for row in batch.results: print( f"Campaign with ID {row.campaign.id} and name " f'"{row.campaign.name}" was found.' ) except GoogleAdsException as ex: print( f'Request with ID "{ex.request_id}" failed with status ' f'"{ex.error.code().name}" and includes the following errors:' ) for error in ex.failure.errors: print(f'\tError with message "{error.message}".') if error.location: for field_path_element in error.location.field_path_elements: print(f"\t\tOn field: {field_path_element.field_name}") sys.exit(1) if __name__ == "__main__": # GoogleAdsClient will read the google-ads.yaml configuration file in the # home directory if none is specified. google_ads_client = GoogleAdsClient.load_from_storage('C:/Users/GoogleAPI/googleads.yaml') parser = argparse.ArgumentParser( description="Lists all campaigns for specified customer." ) # The following argument(s) should be provided to run the example. parser.add_argument( "-c", "--customer_id", type=str, required=True, help="The Google Ads customer ID.", ) args = parser.parse_args() print(args.customer_id) main(google_ads_client, args.customer_id)
But I get this error.
errors { error_code { authorization_error: USER_PERMISSION_DENIED } message: "User doesn\'t have permission to access customer. Note: If you\'re accessing a client customer, the manager\'s customer id must be set in the \'login-customer-id\' header. See https://developers.google.com/google-ads/api/d ocs/concepts/call-structure#login-customer-id" }
customer id works fine for google adwords api.
If anyone knows the answer, I would appreciate it if you let me know. Thank you.
The only thing you need is to pass the CustomerID without dash (-). More specifically, you just need passing the CustomerID with XXXXXXXXXX format instead of XXX-XXX-XXXX. The documentation isn't that informative!