Posts tagged with api

I got this Fatal Error/Uncaught Error while linking with the Google Ads API. I've used the Github code and downloaded library from composer

Fatal error: Uncaught Error: Class "Google\Ads\GoogleAds\Examples\Utils\ArgumentParser" not found in googleAdword\examples\BasicOperations\GetCampaigns.php:44 Stack trace: #0 googleAdword\examples\BasicOperations\GetCampaigns.php(120): Google\Ads\GoogleAds\Examples\BasicOperations\GetCampaigns::main() #1

Tried all these solutions:

  1. reinstalling the lib, and not through zip downloading at first, but through git clone, and then install through composer etc.
  2. In the sample code of GetAccountInformation, there is a CUSTOMER_ID field that is required before you execute the code.(Already set)

I'm using the following lines of code (PHP) after successfuly retriving the media URL and then storing it in the $mediaURL variable for the file request, but it's returning an empty string. Already tried with postman and it returns a 500 internal server error...

** Edited **

self::writeLog('Media URL: '.$mediaURL); self::writeLog('Preparing to download media - id: '.$media_id); $curl = curl_init($mediaURL); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $headers = array(     "Authorization: Bearer ".self::$auth_token, ); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); if (($resp = curl_exec($curl)) === false) {     self::writeLog('cURL Error: '.curl_error($curl)); } else if ($resp == '') {     self::writeLog('Empty string.');     self::writeLog('URL: '.$mediaURL);     self::writeLog('Headers: '.$headers[0]); } else {     self::writeLog($resp); }              
  • writeLog is just a method that I use to write these messages on a txt file.

Meta recently released the cloud api to send messages from Whatsapp business, but I can't send it from the google app script.

I have this code, it runs fine... but it doesn't reach the user

    function SendToUser() {       var headers = {         'Authorization' : 'Bearer ACCESS_TOKEN',         'Content-Type': 'application/json'         };                   var payload = {         "messaging_product": "whatsapp",         "recipient_type": "individual",         "to": "PHONE_NUMBER",         "type": "text",         "text": { // the text object            "preview_url": false,            "body": "MESSAGE_CONTENT"         }        }               var options = {         method: "POST",         headers: headers,         payload: JSON.stringify(payload) // <--- Modified       }            let response = UrlFetchApp.fetch("https://graph.facebook.com/v13.0/FROM_PHONE_NUMBER_ID/messages", options);       Logger.log(response)                  } 

typicallyl in sql, you can use * to mutiply columns, but I am getting an error when trying to do so in my query below within GoogleAds API - anyone face this challenge before.

Code:

import sys, json, io, gzip, sys, os from googleads import adwords import pandas as pd import numpy as np def google_ads_extract(client,customer_id, s3_path,fields,report_type,statuses,date_range, download_version, job_name):   ga_service = client.get_service("GoogleAdsService")   search_request=client.get_type("SearchGoogleAdsStreamRequest")   search_request.customer_id = customer_id     query = """         SELECT           segments.date,           ad_group.id,           ad_group.name,           campaign.id,           campaign.name,           metrics.impressions,           metrics.clicks,           metrics.clicks*metrics.average_cpc as cost,           metrics.conversions,           metrics.ctr,           metrics.average_cpc,           metrics.cost_per_conversion         FROM ad_group         where segments.date BETWEEN 20220427 AND 20220428                   limit 10         """                 print(query)   search_request.query = query      stream = ga_service.search_stream(search_request)      for batch in stream:     for row in batch.results:       print(row)         return 1 

Error:

Request made: , Host: googleads.googleapis.com, Method: /google.ads.googleads.v8.services.GoogleAdsService/SearchStream, RequestId: TevDX_z7WYF-AWUZBMVbnw, IsFault: True, FaultMessage: Error in query: unexpected input *. Traceback (most recent call last): 

Google Ads API recently discontinued an old version - https://ads-developers.googleblog.com/2021/04/upgrade-to-google-ads-api-from-adwords.html.

That being said I am trying to adjust my query to new api standards, and getting the strangest error "unexpected input DURING" -- more detail below. It would seem to be correct per this doc:https://developers.google.com/google-ads/api/docs/samples/get-hotel-ads-performance

Note the use of "DURING" in the example SQL query in the doc above.

Below is my error message and further below is script:

ERROR:

SELECT Date, AdGroupId, AdGroupName, CampaignId, CampaignName, Impressions, Clicks, Cost, Conversions, ConversionRate, Ctr, AverageCpc, CostPerConversion FROM CRITERIA_PERFORMANCE_REPORT WHERE Status IN ('ENABLED', 'PAUSED') DURING 20220427,20220428 Request made: ClientCustomerId:, Host: googleads.googleapis.com, Method: /google.ads.googleads.v8.services.GoogleAdsService/SearchStream, RequestId:, IsFault: True, FaultMessage:  Error in query: unexpected input DURING. 

script:

import sys, json, io, gzip, sys, os from googleads import adwords import pandas as pd import numpy as np def google_ads_extract(client,customer_id, s3_path,fields,report_type,statuses,date_range, download_version, job_name):   ga_service = client.get_service("GoogleAdsService")   search_request=client.get_type("SearchGoogleAdsStreamRequest")   search_request.customer_id = customer_id   query = f"SELECT {', '.join(str(x) for x in fields)} FROM {str(report_type[0])} WHERE Status IN {*statuses,} DURING {date_range}"      # query = "SELECT Date, AdGroupId, AdGroupName, CampaignId, CampaignName, Impressions, Clicks, Cost, Conversions, ConversionRate, Ctr, AverageCpc, CostPerConversion FROM CRITERIA_PERFORMANCE_REPORT WHERE Status IN ('ENABLED', 'PAUSED') DURING 20220427,20220428"                 print(query)   search_request.query = query      stream = ga_service.search_stream(search_request)      for batch in stream:     for row in batch.results:       print(row)         return 1