Posts tagged with google-ads-api

I need to export campaign statistics to .xlsx, which is stored in Google Drive. I substitute the link to this document in the script, and I get this error:

"Service Spreadsheets failed while accessing document with id 1S_rjqsgbjyTKXEo14j_m2xtoIwgHCFi1. (file Code.gs, line 18)".

In the privacy parameters of the document, "editing for everyone who has the link" is configured. How do I solve the problem? I tested these two links: https://docs.google.com/spreadsheets/d/1S_rjqsgbjyTKXEo14j_m2xtoIwgHCFi1/edit#gid=1649084583/ https://drive.google.com/file/d/1S_rjqsgbjyTKXEo14j_m2xtoIwgHCFi1/view?usp=sharing

Here is the script itself.

function main() {  //  var url = 'https://drive.google.com/file/d/1S_rjqsgbjyTKXEo14j_m2xtoIwgHCFi1/view?usp=sharing/';  var datasheet = 'Ali_web_all_acc_export.xlsx';  var columns = 'CampaignName, AdvertisingChannelType, Cost, Date';  var report = 'CAMPAIGN_PERFORMANCE_REPORT';  var selector = 'CampaignName DOES_NOT_CONTAIN "Шашлык15loooool"';  var during = 'YESTERDAY';  // Функция выгрузки  exportReportToSpreadsheet(url, datasheet, columns, report, selector, during); } function exportReportToSpreadsheet(url, datasheet, columns, report, selector, date) {  var spreadsheet = SpreadsheetApp.openByUrl(url);  var sheet = spreadsheet.getSheetByName(datasheet);  var report = AdWordsApp.report(    'SELECT ' + columns + ' ' +    'FROM ' + report + ' ' +    'WHERE ' + selector +' ' +    'DURING '+ date + ' '    );  report.exportToSheet(sheet); } 

I would like to daily monitor the optimization score of Google Ads. It is the metric shown below on the printscreen.

Does anyone know a method ( via API, Supermetrics, or other script ) to return this value to a Google Spreadsheet? I've been searching on Google Ads API but did not find anything so far, and I am curious if anyone got a solution for this.

I am working with the GEO_PERFORMANCE_REPORT in order to fetch data related to the account locations. More specifically, the report I am working with is the User Locations Report, which can be found directly on the AdWords UI.

But I found out that there are some notorious differences for the data obtained via the AdWords API and the data shown via the AdWords UI, and the issues happen specifically with the aforementioned report, but also with the “Geographic Report”. I have applied the corresponding filters for the query, just as it's stated on the official documentation (1 and 2), but even with that, the data differs a lot between both sources.

The query I am constructing ends up being the following one:

Google\AdsApi\AdWords\Query\v201809\ReportQuery {#7426   -awqlString: "SELECT CampaignId, LocationType, Clicks, Impressions, CityCriteriaId, MostSpecificCriteriaId, CountryCriteriaId FROM GEO_PERFORMANCE_REPORT WHERE LocationType = 'LOCATION_OF_PRESENCE' AND IsTargetingLocation IN ['TRUE', 'FALSE'] DURING 20200401,20200430" } 

And the results I am getting (after sorting them by the Clicks metric) are the following: https://www.dropbox.com/s/6xpme91ig6wu1oy/Screenshot%202020-05-13%2018.18.43.png?dl=0. But on the AdWords UI I get the following: https://www.dropbox.com/s/cgtyglbs87lkb1p/Screenshot%202020-05-13%2018.20.20.png?dl=0.

I can see that there are similar issues open at the AdWords forum (1 and 2), but none of them seem fully solved.

Finally, based in the https://developers.google.com/adwords/api/docs/appendix/geotargeting documentation and in some other tests I did by using the MostSpecificCriteriaId, I have the theory that this could be an issue with the zipcodes mapping on the API.

Do you know what is the reason of the discrepancy for the click counts (and also for the impression counts) between both sources of these report?. Help will be appreciated.

I have managed to generate developer_token, oauth client_id, oauth client_secret and oauth refresh_token, using the steps described here, and I've set their values in the googleads.yaml. I did not set any value to client_customer_id, because of an issue in the UI (opened a thread with google adwords product team). However, when I reached this step, I got AuthenticationError.OAUTH_TOKEN_INVALID. I'm using python 3.7, googleads 23.0.1 and code samples from here.

The code I'm running:

client = adwords.AdWordsClient.LoadFromStorage(f'{os.getcwd()}/oauth/googleads.test.yaml') # Initialize appropriate service. campaign_service = client.GetService('CampaignService', version='v201809') # Construct selector and get all campaigns. offset = 0 selector = {     'fields': ['Id', 'Name', 'Status'],     'paging': {         'startIndex': str(offset),         'numberResults': str(PAGE_SIZE)     } } more_pages = True while more_pages:     page = campaign_service.get(selector) # this is the line which raises the exception 

Any suggestions?

Highly appreciate your help, Tal

When I use the generate_refresh_token.py :

pipenv run python authentication/generate_refresh_token.py --client_id xxxxx --client_secret yyyy Log into the Google Account you use to access your AdWords account and go to the following URL: https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=xxxx&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fadwords&state=xxxxx&prompt=consent&access_type=offline 

When I follow the link I get a 403 "org_internal: This client is restricted to users within its organization", I'm using a google account that has the name.surname@domain.com that matches the organization's domain and I have been invited to the project.

What else is need for my google account to be considered part of the "organization"?