Posts tagged with google-ads-api

I'm currently running a script locally to generate reports using GoogleAdsManager API. Prior running the script I've created new service account key in json format as the key type together with ~/googleads.yaml.

Here's the dev guide.

However, I wanted to schedule this script on (AWS Glue).

This is the sample script and the issue I currently faced is :

How do call this method ad_manager.AdManagerClient.LoadFromStorage() from aws? I've stored the credentials (JSON and YAML) in AWS Secrets Manager

from googleads import ad_manager, oauth2 import tempfile import _locale _locale._getdefaultlocale = (lambda *args: ['en_US', 'UTF-8']) ad_unit_id = XXXXXXXXXX def generate_ad_impressions(client):     # Initialize appropriate service.     report_service = client.GetService("ReportService",      version="v202108")     # Initialize a DataDownloader.     report_downloader = client.GetDataDownloader(version="v202108")     # Create statement object to filter for an order.     statement = (         ad_manager.StatementBuilder(version="v202108")         .Where("PARENT_AD_UNIT_ID = :id")         .WithBindVariable("id", mbns_aa_vod_ad_unit_id)         .Limit(None)  # No limit/offset for reports         .Offset(None)     )     report_job = {         "reportQuery": {         "dimensions": ["DATE", "HOUR"],         "columns": [             "AD_SERVER_IMPRESSIONS",         ],         "dateRangeType": "TODAY",         "startDate": {             "year": "2022",             "month": "1",             "day": "25"         },         "endDate": {             "year": "2022",             "month": "1",             "day": "25"         },         "statement": statement.ToStatement(),       }     }     try:         # Run the report and wait for it to finish.         report_job_id = report_downloader.WaitForReport(report_job)     except:         print("Failed to generate report.")         # Change to your preferred export format.         export_format = "CSV_DUMP"         # report_file =         tempfile.NamedTemporaryFile(suffix=".csv.gz",          delete=False)     with open('ad_unit_report.csv.gz', mode='wb') as report_file:         # Download report data.         report_downloader.DownloadReportToFile(report_job_id,          export_format, report_file)         report_file.close()     # Download report data.     downloaded_report =      report_downloader.DownloadReportToFile(report_job_id,      export_format, report_file)     report_file.close()     print('success!') if __name__ == '__main__':    ad_manager_client =     ad_manager.AdManagerClient.LoadFromStorage('path_to_yaml_file')    generate_ad_impressions(ad_manager_client) 

We are using Google ads API and we are getting the refresh_token and access_token from the oauthLibrary.

Now due to some reason (Majorly cause we are using JavaScript and there's no library for JavaScript officially from Google) we are relying on the REST API.

I want to fetch a list of Accounts attached to the the given access token. (no matter manager or not Manager) I just need the list.

I have tried the following endpoint

https://googleads.googleapis.com/v1/customers:listAccessibleCustomers

But I am getting 404 Not found in that, So I think it is discontinued, Any idea how I can fetch the list through REST_API.

I am using google-ads-api. My goal is to get impressions and clicks for specific campaign. These are the things I have done.

  1. created google service account
  2. Downloaded google-ads-library from github
  3. Added clientid , secretid, refresh token to my adsapi.ini file.

When I run the code it gives me error .

Google\ApiCore\ApiException { "message": "The caller does not have permission", "code": 7, "status": "PERMISSION_DENIED", "details": [ { "@type": "type.googleapis.com/google.ads.googleads.v9.errors.GoogleAdsFailure", "errors": [ { "errorCode": { "authorizationError": "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/docs/concepts/call-structure#cid" } ], "requestId": "pKHgfIr99F5XApaPFBnrLQ" } ] }

my adsapi.ini

[GOOGLE_ADS] ; Required Google Ads properties. name = "Google Ads" developerToken = "*****-*******_*" ; Optional. Set a friendly application name identifier. userAgent = "Scraper" ; Optional additional AdWords API settings. ; endpoint = "https://adwords.google.com/" ; isPartialFailure = false ; Optional setting for utility usage tracking in the user agent in requests. ; Defaults to true. ; includeUtilitiesInUserAgent = true [ADWORDS_REPORTING] ; Optional reporting settings. ; isSkipReportHeader = false ; isSkipColumnHeader = false ; isSkipReportSummary = false ; isUseRawEnumValues = false [OAUTH2] ; Required OAuth2 credentials. Uncomment and fill in the values for the ; appropriate flow based on your use case. See the README for guidance: ; https://github.com/googleads/googleads-php-lib/blob/master/README.md#getting-started ; For installed application or web application flow. clientId = "**********************" clientSecret = "********************" refreshToken = "***********************"  For service account flow. ; jsonKeyFilePath = "INSERT_ABSOLUTE_PATH_TO_OAUTH2_JSON_KEY_FILE_HERE" ; scopes = "https://www.googleapis.com/auth/adwords" ; impersonatedEmail = "INSERT_EMAIL_OF_ACCOUNT_TO_IMPERSONATE_HERE" [SOAP] ; Optional SOAP settings. See SoapSettingsBuilder.php for more information. ; compressionLevel = <COMPRESSION_LEVEL> ; wsdlCache = <WSDL_CACHE> [PROXY] ; Optional proxy settings to be used by SOAP requests. ; host = "<HOST>" ; port = <PORT> ; user = "<USER>" ; password = "<PASSWORD>" [LOGGING] ; Optional logging settings. ; soapLogFilePath = "/soap.log" ; soapLogLevel = "INFO" ; reportDownloaderLogFilePath = "path/to/your/report-downloader.log" ; reportDownloaderLogLevel = "INFO" ; batchJobsUtilLogFilePath = "path/to/your/bjutil.log" ; batchJobsUtilLogLevel = "INFO"