Tracking templete to google ads account
I want to add a tracking template on the account level via google ads API, but I am not able to found proper documentation to do it, Is anyone have idea how to do it
Tony-Marketing-API.cn is a vibrant community dedicated to Facebook, Meta,Google Ads api, app development, Instagram, and related technologies. It offers valuable bug solutions, troubleshooting cases, and problem-solving strategies shared by users. Stay updated with real-world solutions, development tips, and the latest trends in digital marketing and app development.
I want to add a tracking template on the account level via google ads API, but I am not able to found proper documentation to do it, Is anyone have idea how to do it
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
To download an image received from the webhook, first, I retrieve the URL with the call to the media endpoint, I execute a curl call to
https://graph.facebook.com/v14.0/xxxxxxxxxxxxxx
where xxxxxxxxxxxxxx is the media id.
The code I use to do that is:
$token = 'sdfsfsdfd'; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://graph.facebook.com/v14.0/xxxxx', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'Authorization: Bearer '.$token, 'Content-Type: application/json' ), )); $response = curl_exec($curl); curl_close($curl); echo $response."<hr>"; $dati = json_decode($response);
and the $response
is:
( [url] => https://lookaside.fbsbx.com/whatsapp_business/attachments/?mid=790316572396xxx&ext=1659596318&hash=ATuHn61BbJOBYzugyRcP6O6UnyY2NSVh3Bb8v12OS3OCzQ [mime_type] => image/jpeg [sha256] => 1cf4a54f0d86c6603d10ad2e9836bc5a98edfabab4b5b8120822be59cbdcxxx0 [file_size] => 253685 [id] => xxxxx [messaging_product] => whatsapp )
After this, I make a new curl call to the obtained URL
$curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $dati->url, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_USERAGENT => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36', CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'Authorization: Bearer '.$token ), )); $response = curl_exec($curl); if(curl_errno($curl)){ throw new Exception(curl_error($curl)); } $getstatusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); if($getstatusCode == 200){ echo 'Downloaded!<hr>'; echo $response; } else{ echo "Status Code: " . $getstatusCode; }
But the $response
obtained is the "something went wrong".
I would have expected a binary blob instead.
Where did I go wrong?
Please note, this issue is in Whatsapp Cloud API not the business API.
I am trying to list all sub accounts in a manager account. I am using the listAccessibleCustomers method in the example below but it is only returning the main customer accounts and not the sub/linked accounts even though I have access to the sub accounts, because I can successfully request a campaign list of one of the sub accounts.
Here is the code I use that's only returning the main accounts.
$this->auth(); $customerServiceClient = $this->$googleAdsClient->getCustomerServiceClient(); // Issues a request for listing all accessible customers. $accessibleCustomers = $customerServiceClient->listAccessibleCustomers(); // Iterates over all accessible customers' resource names. $allitems = array(); foreach ($accessibleCustomers->getResourceNames() as $resourceName) { /** @var string $resourceName */ array_push($allitems,array("name"=>$resourceName)); } return array("count"=>count($accessibleCustomers->getResourceNames()),"items"=>$allitems);
Here is the response:
array(2) { ["count"]=> int(2) ["items"]=> array(2) { [0]=> array(1) { ["name"]=> string(20) "customers/**********" } [1]=> array(1) { ["name"]=> string(20) "customers/**********" } } }
Ultimately it needs to return all the sub/linked accounts of the account that's specified as the loginCustomerId inside the google_ads_php.ini file. Any help would be appreciated.
With the "Google Ads API" - PHP Client Library.
While calling the "GetCampaigns.php
" / "ListAccessibleCustomers.php
" example code. I was still getting this error (below) but found a solution (check answer).
Error -
authorization_error: User doesn't have permission to access customer. Note: If you're accessing a client customer, the manager's customer id must be set in the 'login-customer-id' header. See https://developers.google.com/google-ads/api/docs/concepts/call-structure#cid