Posts tagged with google-api

I have a database of many products withing also many categories. I get the data from several suppliers whom each use their own way to describe category taxonomies. So i am looking to have a more standard approach.

Google uses product category taxonomies for Google shopping: https://www.google.com/basepages/producttype/taxonomy-with-ids.en-US.txt

When adding a shopping feed, google will try to match the product if the category taxonomy is not added manually. More info here: https://support.google.com/merchants/answer/6324436

So i was wondering since Google tries to match automatically, is there an API that supports this feature? Or is there other way to automatically match the products? I do have the EAN/UPC for each product, or alternatively the name and description.

Ideally i would send the EAN/UPS to an API which returns the category ID, but i don't seem to be able to find that solution.

As the database is rather large it would be near impossible to do a manual mapping, so that is not a solution at the moment.

I need some help with the google ad manager API. I am trying to delete a lineitem with the following:

from googleads import ad_manager client = ad_manager.AdManagerClient.LoadFromStorage() def test(id):     line_item_service = client.GetService('LineItemService',version='v202002')     line_item_name = str(id)     statement = (ad_manager.StatementBuilder(version='v202002').Where('OrderId = :OrderId').WithBindVariable('OrderId',app.config['AD_MANAGER']['ORDER_ID']))         response = line_item_service.performLineItemAction(line_item_service.DeleteLineItems(),statement.ToStatement()) 

My problem lies with DeleteLineItems() as I am not sure how to call it correctly. I am not able to find clear usage examples, hence my attempt above. Below are the docs I could find. The error of my current attempt is:

{success: false, error: "<class 'googleads.errors.GoogleAdsValueError'>", message: "Service DeleteLineItems not found"} 

https://developers.google.com/ad-manager/api/reference/v202011/LineItemService.DeleteLineItems https://developers.google.com/ad-manager/api/reference/v202011/LineItemService#performLineItemAction

I have a daily Python script that pulls data from the Google Ads API. I had the v20.0.0 of the google ads library installed. On October 28, it started failing with this error:

Error with message " Version v2 is deprecated. Requests to this version will be blocked." 

I assume this is because of this setup line:

ga_service = client.get_service('GoogleAdsService', version='v2') 

But when I change that to v3 (just a guess, since the error message doesn't tell me what versions are accepted), I get this when I run the script:

ValueError: Specified Google Ads API version "v3" does not exist. Valid API versions are: "v2", "v1" 

I ran pip install --upgrade googleads, which got me up to v25.0.0, but still got the same errors. I then uninstalled and re-installed googleads, but still get the same errors.

I haven't been able to find a migration guide in Google's documentation. Does anyone know how to update the package and script to get it running again?

I'm doing azure function which should regularly get ad reports from Google Ads API and save it to CSV. Copying code from Google documentation left me with this

public static void Run([TimerTrigger("0 22 12 * * *")] TimerInfo myTimer, ILogger log)     {         log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");         RunRequest(new GoogleAdsClient(new GoogleAdsConfig() {              DeveloperToken = "/*token*/",             OAuth2Mode = OAuth2Flow.SERVICE_ACCOUNT,             OAuth2PrnEmail = "/*service account email*/",             OAuth2SecretsJsonPath = "/*service account json*/"         }), "/*client id*/", log);     } public static void RunRequest(GoogleAdsClient client, string customerId, ILogger log)     {         // Get the GoogleAdsService.         GoogleAdsServiceClient googleAdsService = client.GetService(             Services.V5.GoogleAdsService);         // Create the query.         string query = @"/*request*/";         try         {             // Issue a search request.             googleAdsService.SearchStream(customerId, query,                 delegate (SearchGoogleAdsStreamResponse resp)                 {                     using var writer = new StreamWriter($"reports\\report{DateTime.Now}.csv");                     using var csv = new CsvWriter(writer, CultureInfo.InvariantCulture);                     csv.WriteRecords(Report.BuildReports(resp.Results));                 }             );         }         catch (GoogleAdsException e)         {             log.LogInformation("Failure:");             log.LogInformation($"Message: {e.Message}");             log.LogInformation($"Failure: {e.Failure}");             log.LogInformation($"Request ID: {e.RequestId}");             throw;         }     } 

Executing this code gives me an exception with this content:

"Status(StatusCode="Unauthenticated", Detail="Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project."

As I understand I don't need OAuth2 access token when using service account. How to fix this problem, what am I missing?

I am trying to connect to the google ads api using a service account. For analytics there is a good article named Hello Analytics API: Java quickstart for service accounts which explains how to set this up. For Google ads I can't find any documentation online.

So my two questions are:

  1. Is it possible to access the Google Ads API using a service account?
  2. If so, is there something like a Hello Ads API: Java quickstart for service accounts page with information on how to connect to the api with a service account?

UPDATE 2/10

I succeeded in passing the authentication fase. I do get an error when trying to fetch data from the API.

curl.exe --request POST "https://googleads.googleapis.com/v5/customers/******/googleAds:searchStream" --header "Content-Type: application/json"  --header "Authorization: Bearer ******"  --header "developer-token: ******"  --data "{'query': 'SELECT * FROM campaign WHERE segments.date DURING YESTERDAY'}" [{   "error": {     "code": 401,     "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",     "status": "UNAUTHENTICATED",     "details": [       {         "@type": "type.googleapis.com/google.ads.googleads.v5.errors.GoogleAdsFailure",         "errors": [           {             "errorCode": {               "authenticationError": "NOT_ADS_USER"             },             "message": "User in the cookie is not a valid Ads user."           }         ]       }     ]   } } ] 

The google docs say this error is because the account is not associated with an google ads account (https://developers.google.com/google-ads/api/docs/best-practices/common-errors#not_ads_user). The request are being processed by the api, I know this because the request are counted in the google ads api console as errors.

In the Credentials compatible with this API for the google ads Api my service account is listed. I am a little puzzled by the error. The service-account is associated with the google ads account as far as I could tell.