Posts under category google-ads-api

I am using GoogleAdsApi - and I have the query below that works great. :)

report_query = (adwords.ReportQueryBuilder()                   .Select(                     'Date','AdGroupId','AdGroupName','CampaignId','CampaignName',                                      'Impressions','Clicks',                           'Cost'                           ,'Conversions','ConversionRate','Ctr','AverageCpc','CostPerConversion'                           )                    .From('CRITERIA_PERFORMANCE_REPORT')                   .Where('Status').In('ENABLED',                    'PAUSED')                   .During('20200101,20210331')                   .Build()) 

I would like to make this function more dynamic by creating a date variable (I have listed below) and possibly more variables let's say field as well. When I try to create & pass in variables ,it does not work

fields = "'Date','AdGroupId','AdGroupName','CampaignId','CampaignName','Impressions','Clicks','Cost','Conversions','ConversionRate','Ctr','AverageCpc','CostPerConversion'" today = date.today() yesterday = today - timedelta(days = 1) date_filter = f'\'{yesterday.strftime("%Y%m%d")},{today.strftime("%Y%m%d")}\''  report_query = (adwords.ReportQueryBuilder()                       .Select(                        fields                               )                        .From('CRITERIA_PERFORMANCE_REPORT')                       .Where('Status').In('ENABLED',                        'PAUSED')                       .During(date_filter)                       .Build()) 

I get the error below:

googleads.errors.AdWordsReportBadRequestError: Type: QueryError.INVALID_DURING_CLAUSE 

Even though when I pass in the printed value of my date variable, instead of the date variable into .During, it works. So a little confused.

Although I have implemented com.google.android.gms.ads:20.0.0 in my project, still I am not able to use interstitialAd.setAdUnitId(), loadAd.
Here is what I have:

import androidx.multidex.BuildConfig; import com.google.android.gms.ads.Adlistener; import com.google.android.gms.ads.AdRequest; import com.google.android.gms.ads.IntersitialAd; import com.google.android.gms.ads.intersitital.IntersisitalAd; 

Here is where I'm trying to use the method:

public void interstitalLoadAd(Context context){     mInterstitialAd = new InterstitialAd(context);     mInterstitialAd.setAdUnitId(BuildConfig.DEBUG ?         TEST_INTERSTITIAL_AD_UNIT_ID :         INTERSTITIAL_AD_UNIT_ID);     mInterstitialAd.loadAd(new AdRequest.Builder().build());     mInterstitialAd.setAdListener(this); } public void showAd(){     if (mInterstitialAd.isLoaded()){         mInterstitialAd.show();  } 

I am using a Google Ads php library (https://github.com/googleads/googleads-php-lib) to manage my own google ads account, following Google's instructions here (https://developers.google.com/adwords/api/docs/guides/first-api-call)

(I've actually been doing this for many years without a problem, but I recently switched over to using a different project in the Google Cloud Platform, so I had to update my credentials and get a new refresh token)

To get a new refresh token, I ran the php script called GetRefreshTokenWithoutIniFile.php (which allows me to grant offline access and retrieve a new refresh token, which I store in a file auth.ini for future use).

The refresh token last for a few days, before I see this error:

{     "error" : "invalid_grant",     "error_description" : "Token has been expired or revoked." } 

I have been using the above method for years and the refresh token has never expired. However, it now seems to expire every couple of days. I am certainly not 'running out' of refresh tokens (I only request one), and the user is not revoking access (the user is me). For that reason, these similar answers don't help me:

Any more ideas?

I'm trying to extract Search queries by certain rules and I need to get Queries that contain one of the given strings:

    " WHERE " +               " Impressions > " + IMPRESSIONS_THRESHOLD +        " AND AverageCpc > " + AVERAGE_CPC_THRESHOLD +        " AND Query CONTAINS_ANY ['for sale in', 'buy'] " +            " DURING YESTERDAY "); 

But I'm getting error message (tryed different variations):

One of the conditions in the query is invalid. (file Code.gs, line 19) 

Although it seems like I do everything according to Formal Grammar:

String           -> StringSingleQ | StringDoubleQ StringSingleQ    -> '(char)' StringDoubleQ    -> "(char)" StringList       -> [ String (, String)* ] 

If I do just 1 string it works fine:

 " WHERE " +               " Impressions > " + IMPRESSIONS_THRESHOLD +        " AND AverageCpc > " + AVERAGE_CPC_THRESHOLD +        " AND Query CONTAINS 'for sale in' " +             " DURING YESTERDAY "); 

When I execute google-ads python sample code I get the following error

DEBUG:google.auth.transport.requests:Making request: POST https://accounts.google.com/o/oauth2/token DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): accounts.google.com:443 DEBUG:urllib3.connectionpool:https://accounts.google.com:443 "POST /o/oauth2/token HTTP/1.1" 200 None E0421 09:57:53.365121806   21019 ssl_transport_security.cc:1455] Handshake failed with fatal error SSL_ERROR_SSL: error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED. INFO:google.ads.googleads.client:Request ------- Method: /google.ads.googleads.v6.services.GoogleAdsService/SearchStream Host: googleads.googleapis.com Headers: {   "developer-token": "REDACTED",   "x-goog-api-client": "gl-python/3.8.6 grpc/1.37.0 gax/1.26.3",   "x-goog-request-params": "customer_id=" } Request: query: "\n        SELECT\n          campaign.id,\n          campaign.name\n        FROM campaign\n        ORDER BY campaign.id" Response ------- Headers: {} Fault: {   "created": "@1619013473.365323139",   "description": "Failed to pick subchannel",   "file": "src/core/ext/filters/client_channel/client_channel.cc",   "file_line": 5419,   "referenced_errors": [     {       "created": "@1619013473.365317068",       "description": "failed to connect to all addresses",       "file": "src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc",       "file_line": 397,       "grpc_status": 14     }   ] } 

I am behind a corporate network that uses its own certificate for every Internet connection.

  1. Our servers trust the internal certificates. I replaced the CA certs in certifi with our CA certs and urllib3 connects fine to both accounts.google.com and googleads.googleapis.com.

  2. curl to both URLs work fine as well

  3. From the error above looks like urllib3 connected fine but GRPC had an issue. Given curl works, the OS ca certs are fine so where does GRPC pick the ca certs from that I would need to add our corporate issuer certs to?

google-ads: 10.0.0 / python: 3.8.0 / RHEL7