Posts tagged with google-ads-api

I am working with Google Ads API. Based on my use case, I need to get the impressions, clicks, and other statistics about the products based on location(Without creating the campaign).

I contacted the Google Ads API team to address the issue but the doc reference they provided me didn't work in my case. (I'm not using keywords also)

  1. generate forecast metrics

And also the query I used to access the data is...

public void queryTest(long customerId,String campaignId) {     try (GoogleAdsServiceClient googleAdsServiceClient =                  googleAdsClient.getLatestVersion().createGoogleAdsServiceClient()) {         SearchGoogleAdsStreamRequest request =                 SearchGoogleAdsStreamRequest.newBuilder()                         .setCustomerId(Long.toString(customerId))                         .setQuery("SELECT metrics.clicks, metrics.impressions,geographic_view.country_criterion_id FROM geographic_view WHERE geographic_view.country_criterion_id = 1009919")                         .build();         ServerStream<SearchGoogleAdsStreamResponse> stream =                 googleAdsServiceClient.searchStreamCallable().call(request);         for (SearchGoogleAdsStreamResponse response : stream) {             for (GoogleAdsRow googleAdsRow : response.getResultsList()) {                 System.out.println("outPut"+googleAdsRow.getGeographicView());             }         }     } } 

Can someone please help me to resolve this issue?? Thank you!!

I am trying to create ads in Google using REST Api. As per the REST API documentation passing the following request body.

{ "operations": [     {         "create": {             "adGroup": "customers/*********/adGroups/*********",             "status": "PAUSED",             "ad": {                 "expandedTextAd": {                     "headlinePart1": "Example heading",                     "headlinePart2": "Exmaple heading 2",                     "description": "Sample description about ad"                 },                 "finalUrls": [                     "https://www.example.com"                 ]             }         }     } ], "partialFailure": false, "validateOnly": true } 

Endpoint: https://googleads.googleapis.com/v11/customers/{customer_id}/adGroupAds:mutate

Anyone can suggest what I am missing?

Hi I'm trying to connect an python script with google ads api.

I have: Ads Account manager with developer_token and the the account level is in "Test Account" Google ads api -> enabled.

service account added to the api and with file service.json and email like service_acc@project.iam.gserviceaccount.com

google-ads.yaml with

json_key_file_path: 'service.json' impersonated_email: 'service_acc@project.iam.gserviceaccount.com' use_proto_plus: True developer_token: 'developer_token' 

client_ads_id (supuse to be in ads.google.com in help -> customer Id) 10 digits without

I can access client api with client = googleads.client.GoogleAdsClient.load_from_storage() with no error.

Then I try to create a user list with

user_list_service_client = client.get_service("UserListService") user_list_operation = client.get_type("UserListOperation") user_list = user_list_operation.create user_list.name = list_name user_list.description = description user_list.crm_based_user_list.upload_key_type = (    client.enums.CustomerMatchUploadKeyTypeEnum.CONTACT_INFO         ) user_list.membership_life_span = 365 response = user_list_service_client.mutate_user_lists(             customer_id=customer_id, operations=[user_list_operation]         ) 

In the last line I get an error:

errors {   error_code {     authentication_error: NOT_ADS_USER   }   message: "User in the cookie is not a valid Ads user." } 

and in the middle of the exception I got

status = StatusCode.UNAUTHENTICATED 

I don't know how to link the client ads account with the api service account.

I've try to:

  1. The service account is not linked to the ads client. (I've invited to service_acc@project.iam.gserviceaccount.com but... obviously it doesn't arrive and doesn't accept the invitation automatically)
  2. In this doc talk about impersonate, and don't know how to do it

A Google Ads user with permissions on the Google Ads account you want to access. Google Ads does not support using service accounts without impersonation

I am trying to get Video Data but some "Metrics" data I can't get. So please help me with that?

$query = "SELECT campaign.id, ad_group.id, ad_group.name, metrics.impressions, metrics.video_views, metrics.clicks, metrics.video_view_rate, metrics.average_cpv, metrics.cost_micros, metrics.video_quartile_p25_rate, metrics.video_quartile_p50_rate, metrics.video_quartile_p75_rate, metrics.video_quartile_p100_rate, ad_group.status FROM ad_group WHERE ad_group.id IN (11111222233)";         // Issues a search request by specifying page size.         $response = $googleAdsServiceClient->search($customerId, $query, ['pageSize' => self::PAGE_SIZE]);         // Iterates over all rows in all pages and prints the requested field values for each row.         foreach ($response->iterateAllElements() as $googleAdsRow) {             /** @var GoogleAdsRow $googleAdsRow */             printf(                 "Ad group ID %d in campaign ID %d group Status %d Impressions %d clicks %d video_view %d video_view_rate %d average_cpv %d cost_micros %d video_quartile_p25_rate %d video_quartile_p50_rate %d video_quartile_p75_rate %d video_quartile_p100_rate %d ",                 $googleAdsRow->getAdGroup()->getId(),                 $googleAdsRow->getCampaign()->getId(),                 $googleAdsRow->getAdGroup()->getStatus(),                 $googleAdsRow->getMetrics()->getImpressions(),                 $googleAdsRow->getMetrics()->getClicks(),                 $googleAdsRow->getMetrics()->getVideoViews(),                 $googleAdsRow->getMetrics()->getVideoViewRate(),                 $googleAdsRow->getMetrics()->getAverageCpv(),                 $googleAdsRow->getMetrics()->getCostMicros(),                 $googleAdsRow->getMetrics()->getVideoQuartileP25Rate(),                 $googleAdsRow->getMetrics()->getVideoQuartileP50Rate(),                 $googleAdsRow->getMetrics()->getVideoQuartileP75Rate(),                 $googleAdsRow->getMetrics()->getVideoQuartileP100Rate(),                 PHP_EOL             ); 

OUTPUT IS:

Ad group ID 11111222233 in campaign ID 11111222233 group Status 3 Impressions 10552 clicks 2 video_view 6225 video_view_rate 0 average_cpv 20862 cost_micros 129871561 video_quartile_p25_rate 0 video_quartile_p50_rate 0 video_quartile_p75_rate 0 video_quartile_p100_rate 0

I need video_view_rate, video_quartile_p25_rate, video_quartile_p50_rate, video_quartile_p75_rate, video_quartile_p100_rate