Posts tagged with google-ads-api

I'm trying to get the account name and ID of all the Google Ads accounts that the logged user has access to, so the user can later check the stats of each of those accounts.

I've managed to get the IDs using the code on https://developers.google.com/google-ads/api/docs/account-management/listing-accounts?hl=es-419.

But I need the names too and apparently you have to make one API call for each ID to get their account names or any other info.

I've tried with the following Python (Django) code, but it's not working (it probably could be improved a lot and maybe has mistakes, I'm a Python beginner):

def one(request):     client = credenciales(request)     ga_service = client.get_service("GoogleAdsService")     # Get customer resource names from the original code     customer_service = client.get_service("CustomerService")     accessible_customers = customer_service.list_accessible_customers()     customer_resource_names = accessible_customers.resource_names     # Prepare a list to store customer data     list_clients = []     # Iterate through each customer resource name     for resource_name in customer_resource_names:         # Extract the customer ID from the resource name         custom_id = resource_name.split('/')[-1]         # Create a query using the customer_id         query = f'''             SELECT             customer_client.descriptive_name,             customer_client.id,             customer_client.status             FROM customer_client         '''         stream = ga_service.search_stream(customer_id=custom_id, query=query)                  for batch in stream:             for row in batch.results:                 data_clients = {}                 data_clients["descriptive_name"] = row.customer_client.descriptive_name                 data_clients["id"] = row.customer_client.id                 data_clients["status"] = row.customer_client.status                 list_clients.append(data_clients)     # Pass the list of customer data to the template     context = {         'list_clients': list_clients,     }     return render(request, 'one.html', context) 

It gives me the error "authorization_error: USER_PERMISSION_DENIED" (which I don't understand, because it should be automatically showing the accounts that the user has permission to access, I'm not giving those accounts/IDs manually).

I am trying to limit the number of returned keyword ideas. The code works fine, but when I try to set limit to the keywordIdeas that I get using 'pageSize' I get the following error:

An unexpected error occurred: { "message": "Resource has been exhausted (e.g. check quota).", "code": 8, "status": "RESOURCE_EXHAUSTED", "details": [ { "@type": "type.googleapis.com\/google.ads.googleads.v14.errors.GoogleAdsFailure", "errors": [ { "errorCode": { "quotaError": "RESOURCE_EXHAUSTED" }, "message": "Too many requests. Retry in 4 seconds.", "details": { "quotaErrorDetails": { "rateScope": "ACCOUNT", "rateName": "Requests per service per method", "retryDelay": "4s" } } } ], "requestId": "eTMFNxlHYYTzZGDT7Cksfw" } ] }

Which is odd, because I am trying to limit the results and without pageSize this is error is not displayed.

Here is the code:

namespace Google\Ads\GoogleAds\Examples\Planning; 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\Lib\OAuth2TokenBuilder; use Google\Ads\GoogleAds\Lib\V14\GoogleAdsClient; use Google\Ads\GoogleAds\Lib\V14\GoogleAdsClientBuilder; use Google\Ads\GoogleAds\Lib\V14\GoogleAdsException; use Google\Ads\GoogleAds\Util\V14\ResourceNames; use Google\Ads\GoogleAds\V14\Enums\KeywordPlanNetworkEnum\KeywordPlanNetwork; use Google\Ads\GoogleAds\V14\Errors\GoogleAdsError; use Google\Ads\GoogleAds\V14\Services\GenerateKeywordIdeaResult; use Google\Ads\GoogleAds\V14\Services\KeywordAndUrlSeed; use Google\Ads\GoogleAds\V14\Services\KeywordSeed; use Google\Ads\GoogleAds\V14\Services\UrlSeed; use Google\ApiCore\ApiException; function generateKeywordIdeas($customerId, $url, $language, $locationId){     try {         // Google Ads API Configurations        $config = [             'developerToken' => '***',             'clientId' => '***',             'clientSecret' => '***',             'refreshToken' => '***',             'loginCustomerId' => '***',              'useSandbox' => true, // Set to true if you want to use the sandbox environment for testing.             'useImplicitConversion' => false, // Set to true if you want to automatically convert currency and units.         ];                 $oAuth2Credential = (new OAuth2TokenBuilder())         ->fromFile($_SERVER['DOCUMENT_ROOT'] . '/google-ads-php/google_ads_php.ini')         ->build();         $googleAdsClient = (new GoogleAdsClientBuilder())         ->fromFile($_SERVER['DOCUMENT_ROOT'] . '/google-ads-php/google_ads_php.ini')         ->withOAuth2Credential($oAuth2Credential)         ->build();                  $pageUrl = null;         $keywords = ['marketing','seo','advertising'];                        $locationIds = [21167];         $geoTargetConstants =  array_map(function ($locationId) {             return ResourceNames::forGeoTargetConstant($locationId);         }, $locationIds);         $keywordPlanIdeaServiceClient = $googleAdsClient->getKeywordPlanIdeaServiceClient();               $requestOptionalArgs = [];         if (empty($keywords)) {             // Only page URL was specified, so use a UrlSeed.             $requestOptionalArgs['urlSeed'] = new UrlSeed(['url' => $pageUrl]);         } elseif (is_null($pageUrl)) {             // Only keywords were specified, so use a KeywordSeed.             $requestOptionalArgs['keywordSeed'] = new KeywordSeed(['keywords' => $keywords]);         } else {             // Both page URL and keywords were specified, so use a KeywordAndUrlSeed.             $requestOptionalArgs['keywordAndUrlSeed'] =                 new KeywordAndUrlSeed(['url' => $pageUrl, 'keywords' => $keywords]);         }         $response = $keywordPlanIdeaServiceClient->generateKeywordIdeas(             [                 // Set the language resource using the provided language ID.                 'language' => ResourceNames::forLanguageConstant(1000),                 'customerId' => ***,                 // Add the resource name of each location ID to the request.                 'geoTargetConstants' => $geoTargetConstants,                 'keywordPlanNetwork' => KeywordPlanNetwork::GOOGLE_SEARCH,                 'pageSize'=>50                            ]+$requestOptionalArgs         );         // Iterate over the results and print its detail.         foreach ($response->iterateAllElements() as $result) {         var_dump($result->getText());                 } catch (GoogleAdsException $e) {         printf(             "An error occurred while generating keyword ideas: %s\n",             $e->getMessage()         );     } catch (\Throwable $e) {         printf(             "An unexpected error occurred: %s\n",             $e->getMessage()         );     } } generateKeywordIdeas($customerId, $url, $language, $locationId); ?> 

I am using Admob (react-native-admob-native-ads) package with my react-native(android) app. I have a problem with NativeAd, onAdImpression callback on NatveAd is not called even after the ad is loaded and display on screen. But when i open my app from app-tray onAdImpression called correctly.

Here is my code for NativeAd

<NativeAd ref={nativeAdViewRef} adUnitID={NATIVE_AD_ID} onAdLoaded={()=>console.log('Ad Loaded successfully')} onAdImpression={()=>console.log 'impression count'}/>

Here Ad Loaded successfully printed in concole but impression count not until i open my app from app-tray

I've built an app with Expo and successfully published it in Apple's App Store and Google's Play Store. Included in it is AdMob for running ads in the app, and Firebase for analytics.

Now I'm using Google Ads to promote it, so added two campaigns, one for Android and one for iOS. The Android campaign has been running well for the past few weeks, but the iOS has done nothing at all (no impressions, no costs).

I tried adding a new conversion action for tracking first_open event from Firebase. I can see in Firebase and Google Analytics that that event has been tracked for iOS. But, the status of the action in Google Ads has been on No recent conversions for two weeks now, so that doesn't seem to work.

I tried following the instructions for React Native Google Mobile Ads, adding the sk_ad_network_items into my app.json. Also made sure the project settings in Firebase are set up correctly.

Am I missing something? Anyone got this working?