context_error: The operation is not allowed for the given context
I am trying to create a new campaing using google ads api with php client library. And simply getting this error. I will post whole php code here since I don't really know what this error is about. The console outputs the following:
[2022-02-22T18:00:13.039301+03:00] google-ads.WARNING: Request made: Host: "googleads.googleapis.com", Method: "/google.ads.googleads.v10.services.CampaignBudgetService/MutateCampaignBudgets", CustomerId: 9445807394, RequestId: "ozBYeKzMcMLizUbsO0r8_w", IsFault: 1, FaultMessage: "["The operation is not allowed for the given context."]" [2022-02-22T18:00:13.042848+03:00] google-ads.NOTICE: Request ------- Method Name: /google.ads.googleads.v10.services.CampaignBudgetService/MutateCampaignBudgets Host: googleads.googleapis.com Headers: { "x-goog-api-client": "gl-php\/7.4.27 gccl\/14.0.0 gapic\/14.0.0 gax\/1.11.4 grpc\/1.43.0 rest\/1.11.4", "x-goog-request-params": "customer_id=9445807394", "developer-token": "REDACTED", "login-customer-id": "6165712462" } Request: {"customerId":"9445807394","operations":[{"create":{"name":"Test Budget #2022-02-22T18:00:12.342+03:00","amountMicros":"500000","deliveryMethod":"STANDARD"}}]} Response ------- Headers: { "request-id": "ozBYeKzMcMLizUbsO0r8_w", "date": "Tue, 22 Feb 2022 15:00:12 GMT", "alt-svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"" } Fault ------- Status code: 3 Details: Request contains an invalid argument. Failure: {"errors":[{"errorCode":{"contextError":"OPERATION_NOT_PERMITTED_FOR_CONTEXT"},"message":"The operation is not allowed for the given context.","location":{"fieldPathElements":[{"fieldName":"operations","index":0}]}}],"requestId":"ozBYeKzMcMLizUbsO0r8_w"} Request with ID 'ozBYeKzMcMLizUbsO0r8_w' has failed. Google Ads failure details: context_error: The operation is not allowed for the given context
The code is as follows:
<?php /** * Copyright 2018 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ namespace Google\Ads\GoogleAds\Examples\BasicOperations; require __DIR__ . '/vendor/autoload.php'; use GetOpt\GetOpt; use Google\Ads\GoogleAds\Examples\Utils\ArgumentNames; use Google\Ads\GoogleAds\Examples\Utils\ArgumentParser; use Google\Ads\GoogleAds\Examples\Utils\Helper; use Google\Ads\GoogleAds\Lib\V10\GoogleAdsClient; use Google\Ads\GoogleAds\Lib\V10\GoogleAdsClientBuilder; use Google\Ads\GoogleAds\Lib\V10\GoogleAdsException; use Google\Ads\GoogleAds\Lib\OAuth2TokenBuilder; use Google\Ads\GoogleAds\V10\Common\ManualCpc; use Google\Ads\GoogleAds\V10\Enums\AdvertisingChannelTypeEnum\AdvertisingChannelType; use Google\Ads\GoogleAds\V10\Enums\BudgetDeliveryMethodEnum\BudgetDeliveryMethod; use Google\Ads\GoogleAds\V10\Enums\CampaignStatusEnum\CampaignStatus; use Google\Ads\GoogleAds\V10\Errors\GoogleAdsError; use Google\Ads\GoogleAds\V10\Resources\Campaign; use Google\Ads\GoogleAds\V10\Resources\Campaign\NetworkSettings; use Google\Ads\GoogleAds\V10\Resources\CampaignBudget; use Google\Ads\GoogleAds\V10\Services\CampaignBudgetOperation; use Google\Ads\GoogleAds\V10\Services\CampaignOperation; use Google\ApiCore\ApiException; /** This example adds new campaigns to an account. */ class AddCampaigns{ private const CUSTOMER_ID = '9445807394'; private const NUMBER_OF_CAMPAIGNS_TO_ADD = 2; public static function main(){ // Either pass the required parameters for this example on the command line, or insert them // into the constants above. $options = (new ArgumentParser())->parseCommandArguments([ ArgumentNames::CUSTOMER_ID => GetOpt::REQUIRED_ARGUMENT ]); // Generate a refreshable OAuth2 credential for authentication. $oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build(); // Construct a Google Ads client configured from a properties file and the // OAuth2 credentials above. $googleAdsClient = (new GoogleAdsClientBuilder()) ->fromFile() ->withOAuth2Credential($oAuth2Credential) ->build(); try { self::runExample( $googleAdsClient, $options[ArgumentNames::CUSTOMER_ID] ?: self::CUSTOMER_ID ); } catch (GoogleAdsException $googleAdsException) { printf( "Request with ID '%s' has failed.%sGoogle Ads failure details:%s", $googleAdsException->getRequestId(), PHP_EOL, PHP_EOL ); foreach ($googleAdsException->getGoogleAdsFailure()->getErrors() as $error) { /** @var GoogleAdsError $error */ printf( "\t%s: %s%s", $error->getErrorCode()->getErrorCode(), $error->getMessage(), PHP_EOL ); } exit(1); } catch (ApiException $apiException) { printf( "ApiException was thrown with message '%s'.%s", $apiException->getMessage(), PHP_EOL ); exit(1); } } /** * Runs the example. * * @param GoogleAdsClient $googleAdsClient the Google Ads API client * @param int $customerId the customer ID */ public static function runExample(GoogleAdsClient $googleAdsClient, int $customerId){ // Creates a single shared budget to be used by the campaigns added below. $budgetResourceName = self::addCampaignBudget($googleAdsClient, $customerId); // Configures the campaign network options. $networkSettings = new NetworkSettings([ 'target_google_search' => true, 'target_search_network' => true, 'target_content_network' => false, 'target_partner_search_network' => false ]); $campaignOperations = []; for ($i = 0; $i < self::NUMBER_OF_CAMPAIGNS_TO_ADD; $i++) { // Creates a campaign. // [START add_campaigns_1] $campaign = new Campaign([ 'name' => 'Test #' . Helper::getPrintableDatetime(), 'advertising_channel_type' => AdvertisingChannelType::SEARCH, // Recommendation: Set the campaign to PAUSED when creating it to prevent // the ads from immediately serving. Set to ENABLED once you've added // targeting and the ads are ready to serve. 'status' => CampaignStatus::PAUSED, // Sets the bidding strategy and budget. 'manual_cpc' => new ManualCpc(), 'campaign_budget' => $budgetResourceName, // Adds the network settings configured above. 'network_settings' => $networkSettings, // Optional: Sets the start and end dates. 'start_date' => date('Ymd', strtotime('+1 day')), 'end_date' => date('Ymd', strtotime('+1 month')) ]); // [END add_campaigns_1] // Creates a campaign operation. $campaignOperation = new CampaignOperation(); $campaignOperation->setCreate($campaign); $campaignOperations[] = $campaignOperation; } // Issues a mutate request to add campaigns. $campaignServiceClient = $googleAdsClient->getCampaignServiceClient(); $response = $campaignServiceClient->mutateCampaigns($customerId, $campaignOperations); printf("Added %d campaigns:%s", $response->getResults()->count(), PHP_EOL); foreach ($response->getResults() as $addedCampaign) { /** @var Campaign $addedCampaign */ print "{$addedCampaign->getResourceName()}" . PHP_EOL; } } /** * Creates a new campaign budget in the specified client account. * * @param GoogleAdsClient $googleAdsClient the Google Ads API client * @param int $customerId the customer ID * @return string the resource name of the newly created budget */ // [START add_campaigns] private static function addCampaignBudget(GoogleAdsClient $googleAdsClient, int $customerId){ // Creates a campaign budget. $budget = new CampaignBudget([ 'name' => 'Test Budget #' . Helper::getPrintableDatetime(), 'delivery_method' => BudgetDeliveryMethod::STANDARD, 'amount_micros' => 500000 ]); // Creates a campaign budget operation. $campaignBudgetOperation = new CampaignBudgetOperation(); $campaignBudgetOperation->setCreate($budget); // Issues a mutate request. $campaignBudgetServiceClient = $googleAdsClient->getCampaignBudgetServiceClient(); $response = $campaignBudgetServiceClient->mutateCampaignBudgets( $customerId, [$campaignBudgetOperation] ); /** @var CampaignBudget $addedBudget */ $addedBudget = $response->getResults()[0]; printf("Added budget named '%s'%s", $addedBudget->getResourceName(), PHP_EOL); return $addedBudget->getResourceName(); } // [END add_campaigns] } AddCampaigns::main();
How to fix this error? Or what is it about?
google ads api - "argument should be integer or bytes-like object, not 'str'"
I've been trying to follow the examples and documentation for the python ad_manager library for the google ads API, but I haven't been able to complete a successful request. I currently have my developer token, client_id, client_secret, and refresh_token in my google ads YAML file, but I'm constantly getting the error "argument should be integer or bytes-like object, not 'str'" when calling the function WaitForReport following the example code below. I was wondering if anyone had any advice on how I could tackle this issue.
import tempfile # Import appropriate modules from the client library. from googleads import ad_manager from googleads import errors def main(client): # Initialize a DataDownloader. report_downloader = client.GetDataDownloader(version='v202111') # Create report job. report_job = { 'reportQuery': { 'dimensions': ['COUNTRY_NAME', 'LINE_ITEM_ID', 'LINE_ITEM_NAME'], 'columns': ['UNIQUE_REACH_FREQUENCY', 'UNIQUE_REACH_IMPRESSIONS', 'UNIQUE_REACH'], 'dateRangeType': 'REACH_LIFETIME' } } try: # Run the report and wait for it to finish. report_job_id = report_downloader.WaitForReport(report_job) except errors.AdManagerReportError as e: print('Failed to generate report. Error was: %s' % e) # Change to your preferred export format. export_format = 'CSV_DUMP' report_file = tempfile.NamedTemporaryFile(suffix='.csv.gz', delete=False) # Download report data. report_downloader.DownloadReportToFile( report_job_id, export_format, report_file) report_file.close() # Display results. print('Report job with id "%s" downloaded to:\n%s' % ( report_job_id, report_file.name)) if __name__ == '__main__': # Initialize client object. ad_manager_client = ad_manager.AdManagerClient.LoadFromStorage() main(ad_manager_client)
Edit: Below is the stack trace:
Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/googleads/common.py", line 984, in MakeSoapRequest return soap_service_method( File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/zeep/proxy.py", line 46, in __call__ return self._proxy._binding.send( File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/zeep/wsdl/bindings/soap.py", line 135, in send return self.process_reply(client, operation_obj, response) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/zeep/wsdl/bindings/soap.py", line 229, in process_reply return self.process_error(doc, operation) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/zeep/wsdl/bindings/soap.py", line 317, in process_error raise Fault( zeep.exceptions.Fault: Unknown fault occured During handling of the above exception, another exception occurred: Traceback (most recent call last): File "google_ads.py", line 72, in <module> main(ad_manager_client) File "google_ads.py", line 33, in main1 report_job_id = report_downloader.WaitForReport(report_job) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/googleads/ad_manager.py", line 784, in WaitForReport report_job_id = service.runReportJob(report_job)['id'] File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/googleads/common.py", line 989, in MakeSoapRequest underlying_exception = e.detail.find( TypeError: argument should be integer or bytes-like object, not 'str'
Google publisher tag showing coloured box randomly
I am trying to add googletags multiple times on the page. In some places on the page ads are displayed correctly and in some places, I see the box as shown in the attached screenshot.
Code sample:
const slot = googletag.defineSlot( options.addUnit, options.sizes, options.containerId, )?.addService(googletag.pubads()); googletag.pubads().enableSingleRequest(); // Disable initial load. googletag.pubads().disableInitialLoad(); // Start ad fetching googletag.enableServices(); googletag.pubads().refresh([slot]);
The above code is called multiple times with some different slot level targeting parameters like 'pos'.
In total, I am calling it 8 times on the page and 4 times div elements are injected dynamically in the page. Sometimes I see one generic box sometimes two or at times 3, this behavior is random. See the second screenshot after I refresh the page.
Authentication Mechanism for Gupshup WhatsApp pintegration with my own Business API
What is the best and safest authentication strategy to support Gupshup(WhatsApp) and my own Business API integration? We independently support JWT/Oauth based authentication on our API, but in case of WhatsApp Integration, we will just have a phone number and not a user ID & password.