Posts under category google-ads-api

I'm using Google AdWords Python SDK to create ResponsiveDisplayAds. My code is like below.

adgroup_ad_service = adwords_client.GetService(     service_name = "AdGroupAdService",     version = "v201809" ) operations = [{     'operator': 'ADD',     'operand': {         'xsi_type': 'AdGroupAd',         'adGroupId': '<AD_GROUP_ID>',         'ad': {             'xsi_type': 'ResponsiveDisplayAd',             'marketingImage': {                 'mediaId': '<MEDIA_ID>'             },             'shortHeadline': 'Short Headline',             'longHeadline': 'This is a very long headline',             'description': 'This is a description',             'businessName': 'Test Business Name',             'finalUrls': ['https://www.google.com'],             'squareMarketingImage': {                 'mediaId': '<MEDIA_ID>'             }         },         'status': 'PAUSED'     } }] ads_response = adgroup_ad_service.mutate(operations) print("AD RESPONSE : {}".format(ads_response)) 

But It's giving me, AdGroupAdError.CANNOT_CREATE_DEPRECATED_ADS.

According to the documentation it describe this error as An ad of this type is deprecated and cannot be created. Only deletions are permitted..

But in documentation of the AdGroupAd ResponsiveDisplayAd, is one of the accepted Ad types.

So it would be great if someone can point me a direction to resolve this issue.

our marketing team is running adwords for our google store ad campaign. they wants to check if an app installation event is triggered when a user clicked on the advertised link or not. (probably like conversion tracking for installation via adwords). is there anyway we can do this?

I'm developing an integration between existing CPA system and Google AdWords. Conversions are stored in the system, and the goal is to periodically, as a background task, parse conversions and send them to user's Google Ad account.

Here's what I figured so far:

  1. I need a google application to which users will grant permission to push data to their ad account.
  2. I need Oauth2 credentials to authorize my application AND users credentials to authorize the API request.

The process of creating and storing gclid is out of concern right now.

I use php client library https://github.com/googleads/googleads-php-lib, which has adsapi_php.ini configuration file. In this file, there are developer token, manager's account client ID, and OAuth2 credentials (cliendId, clientSecret, refreshToken).

However, when user gives access to my application via consent screen, I create OAuth2 object as follows:

 $oAuth2Credential = new OAuth2([         'authorizationUri'   => 'https://accounts.google.com/o/oauth2/v2/auth',         'tokenCredentialUri' => 'https://www.googleapis.com/oauth2/v4/token',         'redirectUri'        => '<myEndpoint>',         'clientId'           => '<myClientId>',         'clientSecret'       => '<myClientSecret>',         'scope'              => 'https://www.googleapis.com/auth/adwords'     ]); 

If I understand correctly, I absolutely need to have web application OAuth credentials in order to have a callback to save user's access and refresh tokens, to use them later in my background task.

1) Does this credentials and the ones in adsapi_ini.php file has to be the same?

I've tried to generate a refresh token for my web type credentials to use in conf file, but it did not work. Right now I'm able to get a valid response when I have credentials for application type 'other' in the configuration file, and 'web' application credentials in Oauth2 object for getting user credentials, but I'm not sure this is correct way to do it.

2) How to authorize API request to push data to certain user's account?

Here's sample code:

 $session = (new AdWordsSessionBuilder())         ->fromFile()         ->withOAuth2Credential($oAuth2Credential)         ->withClientCustomerId('<client-customer-id>')         ->build(); 

As I understand, session object is essential to build any further queries, including uploding conversions.

->fromFile() uses mentined configuration file to get my token and Auth data - basically authorize my application.

$oAuth2Credential is the OAuth2 object containing specific user's authorization data. The problem is that in documentation, this object is created by builder and uses the same method fromFile(), and I don't understand what data it must contain.

I store access_token and refresh_token in my database, and right now I'm building OAuth object as follows:

$oAuth2Credential = new OAuth2([         'authorizationUri'   => 'https://accounts.google.com/o/oauth2/v2/auth',         'tokenCredentialUri' => 'https://www.googleapis.com/oauth2/v4/token',         'redirectUri'        => '<myEndpoint>',         'clientId'           => '<myClientId>',         'clientSecret'       => '<myClientSecret>',         'scope'              => 'https://www.googleapis.com/auth/adwords',         'access_token'       => '<user_access_token>'     ]); 

So basically just adding access_token to parameters that I'm using for getting this token from user. It works, but doesn't look like correct way to do this.

3) How to manage user's token expiration?

Documentation says that client library automatically handles refreshing tokens, but I don't understand how it will work in my case. Do I need to pass access_token with refresh_token in OAuth object when making API request and then it will refresh automatically, or do I need separate worker to periodically refresh user tokens to keep them valid?

I want to fetch location details for all the ads from google adwords but I am getting null entries.I am not able to get any data from adwords api .Help me in That as according to my knowledge there is not problem with my code and I am not able to find any solution for that.My code that I have tried is written below.

 public void GetLocationAds()             {                 AdWordsUser user = new AdWordsUser();                 {                     try                     {                         int offset = 0;                                                                 // Create selector.                         using (CampaignCriterionService campaignCriterionService =                             (CampaignCriterionService)user.GetService(AdWordsService.v201809.CampaignCriterionService))                         {                             Selector selector = new Selector()                             {                                 fields = new string[]                              {                                   CampaignCriterion.Fields.CampaignId,                                     CampaignCriterion.Fields.CampaignCriterionStatus,                                      //Location.Fields.LocationName,                                      //Location.Fields.CriteriaType,                                      //Location.Fields.ParentLocations,                                      //LocationCriterion.Fields.CanonicalName,                                      //LocationCriterion.Fields.CountryCode,                                   CampaignCriterion.Fields.IsNegative,                              },                            //     predicates = new Predicate[]                            //{                            //    Predicate.Equals( "CriteriaType","LOCATION"),                            //},                                 paging = Paging.Default,                                 ordering = new OrderBy[]                        {                                 OrderBy.Asc(  CampaignCriterion.Fields.CampaignId)                        }                             };                             CampaignCriterionPage page = new CampaignCriterionPage();                             do                             {                                 // Get the ad groups.                                  page = campaignCriterionService.get(selector);                                 // Display the results.                                 if (page != null && page.entries != null)                                 {                                     int j = selector.paging.startIndex;                                     foreach (CampaignCriterion campaignCriterion in page.entries)                                     {                                         var campaignId = campaignCriterion.campaignId;                                         bool IsLocation = campaignCriterion.isNegative;                                         var CampaignCriterionType = campaignCriterion.CampaignCriterionType;                                     }                                 }                                 else                                 {                                     Console.Write("No campaignCriterion were found.");                                 }                                 selector.paging.IncreaseOffset();                             }                             while (selector.paging.startIndex < page.totalNumEntries);                         }                     }                     catch (Exception ex)                     {                     }                 }             } 

Kindly help me in that.

python3.8

My code:

from googleads import adwords def execute_request():     adwords_client = adwords.AdWordsClient.LoadFromStorage(path="google_general/googleads.yaml")     campaign_service = adwords_client.GetService('CampaignService', version='v201809')     pass context["dict_list"] = execute_request() 

Traceback:

Traceback (most recent call last):   File "/home/michael/pycharm-community-2019.3.2/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_xml.py", line 282, in frame_vars_to_xml     xml += var_to_xml(v, str(k), evaluate_full_value=eval_full_val)   File "/home/michael/pycharm-community-2019.3.2/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_xml.py", line 369, in var_to_xml     elif hasattr(v, "__len__") and not is_string(v):   File "/home/michael/PycharmProjects/ads3/venv/lib/python3.8/site-packages/googleads/common.py", line 694, in __getattr__     raise googleads.errors.GoogleAdsValueError('Service %s not found' % attr) googleads.errors.GoogleAdsValueError: Service __len__ not found Unexpected error, recovered safely. 

googleads.yaml about logging

logging:   version: 1   disable_existing_loggers: False   formatters:     default_fmt:       format: ext://googleads.util.LOGGER_FORMAT     handlers:       default_handler:         class: logging.StreamHandler         formatter: default_fmt         level: DEBUG     loggers:     # Configure root logger       "":       handlers: [default_handler]       level: DEBUG 

I've just started studying the API. Namely, I'm trying to execute my first request (https://developers.google.com/adwords/api/docs/guides/first-api-call#make_your_first_api_call)

Could you help me with this problem? At least how to localize it more precisely.