Posts under category Google

I'm trying to pull data from my Google Ads account using their API. I'm using Python

In the code example there is a query where I can specify the date range from which I want to collect results from my campaign.

I would like to dynamically change de date everyday and run the script to get data from the previous day.

My idea was to create a variable with the previous day date in the format Google API is requiering it, named "yesterday".

But I don't know how to use this variable into the query

Here's a part of the code :

import argparse import sys from google.ads.googleads.client import GoogleAdsClient from google.ads.googleads.errors import GoogleAdsException from datetime import * yesterday_date = date.today() - timedelta(days=1) yesterday = yesterday_date.strftime("%Y-%m-%d") def main(client, customer_id): ga_service = client.get_service("GoogleAdsService") query = """     SELECT       campaign.id,       campaign.name,       metrics.cost_micros,       campaign.status     FROM campaign     WHERE segments.date = '2021-08-19'         """ # Issues a search request using streaming. response = ga_service.search_stream(customer_id=customer_id, query=query) for batch in response:     for row in batch.results:         print(             f"Campaign with ID {row.campaign.id}, status is {row.campaign.status}, cost is {row.metrics.cost_micros} and name "             f'"{row.campaign.name}" was found.'         ) 

I would like to do something like this :

WHERE segments.date = yesterday 

I've tried to use sqlite3 library, to use cursor.execute() but I don't know how to use them properly.

I'm a beginner so the answer might be very easy.

Hope you all are doing well. I am new working with Google ads api. I have to retrieve information regarding keywords i.e how many people searched certain keywords , how many clicks and so on... so I have created a manager account on Google ads and under that I have created client account. In client account I have added keywords under keyword planner and I am getting all information mentioned above but I want to get it through REST API in python.

I have everything needed to access API: (Developer token login_customer_id Client ID Client Secret refresh token) I have given this information in the .yaml file. and I assume login_customer_id is the manager account id. Below is the code to access all the keywords information. here I have given the client_idfrom which I want to access keywords information.

import argparse import sys from google.ads.googleads.client import GoogleAdsClient from google.ads.googleads.errors import GoogleAdsException

def main(client, customer_id): ga_service = client.get_service("GoogleAdsService")

query = """     SELECT       campaign.id,       campaign.name,       ad_group.id,       ad_group.name,       ad_group_criterion.criterion_id,       ad_group_criterion.keyword.text,       ad_group_criterion.keyword.match_type,       metrics.impressions,       metrics.clicks,       metrics.cost_micros     FROM keyword_view WHERE segments.date DURING LAST_7_DAYS     AND campaign.advertising_channel_type = 'SEARCH'     AND ad_group.status = 'ENABLED'     AND ad_group_criterion.status IN ('ENABLED', 'PAUSED')     ORDER BY metrics.impressions DESC     LIMIT 50""" # Issues a search request using streaming. search_request = client.get_type("SearchGoogleAdsStreamRequest") search_request.customer_id = customer_id search_request.query = query response = ga_service.search_stream(search_request) for batch in response:     for row in batch.results:         campaign = row.campaign         ad_group = row.ad_group         criterion = row.ad_group_criterion         metrics = row.metrics         print(             f'Keyword text "{criterion.keyword.text}" with '             f'match type "{criterion.keyword.match_type.name}" '             f"and ID {criterion.criterion_id} in "             f'ad group "{ad_group.name}" '             f'with ID "{ad_group.id}" '             f'in campaign "{campaign.name}" '             f"with ID {campaign.id} "             f"had {metrics.impressions} impression(s), "             f"{metrics.clicks} click(s), and "             f"{metrics.cost_micros} cost (in micros) during "             "the last 7 days."         ) # [END get_keyword_stats] 

if name == "main":

googleads_client=GoogleAdsClient.load_from_storage("C:\Users\AnoshpaBansari\PycharmProjects\GoogleAPI\src\creds\googleads.yaml")

parser = argparse.ArgumentParser(     description=("Retrieves a campaign's negative keywords.") ) # The following argument(s) should be provided to run the example. #parser.add_argument(  #   "-c",   #  "--customer_id",    # type=str,     #required=True,     #help="The Google Ads customer ID.", #) #args = parser.parse_args() try:     main(googleads_client, "----------") except GoogleAdsException as ex:     print(         f'Request with ID "{ex.request_id}" failed with status '         f'"{ex.error.code().name}" and includes the following errors:'     )     for error in ex.failure.errors:         print(f'\tError with message "{error.message}".')         if error.location:             for field_path_element in error.location.field_path_elements:                 print(f"\t\tOn field: {field_path_element.field_name}")     sys.exit(1) 

but when I run the code I receive this error. I don't know what I am doing wrong.. Can anyone please help? enter image description here

I am trying to update the AmoutMicros of Budget but I don't receive error, just not update the budget:

        CampaignBudget budget = new CampaignBudget()         {             ResourceName = ResourceNames.CampaignBudget(customerId, budgetId),             AmountMicros = (price + amount) * 100000,             Id = budgetId         };         CampaignBudgetOperation budgetOperation = new CampaignBudgetOperation()         {             Create = budget,             UpdateMask = FieldMasks.AllSetFieldsOf(budget),         };         try         {             MutateCampaignBudgetsResponse responseBudget =              budgetService.MutateCampaignBudgets(             customerId.ToString(), new CampaignBudgetOperation[] { budgetOperation            });             foreach(MutateCampaignBudgetResult result in responseBudget.Results)             {                 updateResponse.CampignId = campaignId;                 updateResponse.Updated = true;                 Console.WriteLine(result);             }             return updateResponse;         }         catch (GoogleAdsException e)         {             Console.WriteLine("Failure:");             Console.WriteLine($"Message: {e.Message}");             Console.WriteLine($"Failure: {e.Failure}");             Console.WriteLine($"Request ID: {e.RequestId}");             return updateResponse;             throw;         } 

This code don't show me a exception, apparently it was update, but, when I go at Google Ads Dashboard, the amout still the same.

I read the documentation but I didn't find an update of a budget.

I had banner, interstitial, and reward ads on one of my apps. The ads seemed to have been working for the past 2 months and then suddenly yesterday both android and iOS apps stopped showing ads:

iOS Error: code: 1, domain: com.google.admob, message: Request Error: No ad to show

Android: code: 3, domain: com.google.android.gms.ads, message: No ad config

It's also strange that both the apps have different error codes.

Package: google_mobile_ads: ^0.12.1+1

Code:

Container(      height: bannerAd.size.height.toDouble(),      child: AdWidget(             ad: bannerAd,             ),      margin: EdgeInsets.symmetric(vertical: 30), ) 

Note:

  1. The test ads seem to work just fine.
  2. The Android and iOS apps have been published on the stores and have been working just fine for the past 2 months.