Posts tagged with google-ads-api

I'm making Web Application for Extracting data from Youtube Videos then analyze it and find the best keywords

All I need is finding the best keywords from Keywords Planner of Google depends on the volume search i did extract the youtube video data, I followed this library https://github.com/googleads/googleads-php-lib

I have Clientid, Clientsecret and Developer Token After I installed the library successfully and tried to test GetCampaigns() class, I get this Error

Fatal error: Uncaught InvalidArgumentException: All of 'clientId', 'clientSecret', and 'refreshToken' must be set when using installed/web application flow. in C:\xampp\htdocs\seosystem\googleads-php-lib\src\Google\AdsApi\Common\OAuth2TokenBuilder.php:225 Stack trace: #0 C:\xampp\htdocs\seosystem\googleads-php-lib\src\Google\AdsApi\Common\OAuth2TokenBuilder.php(173): Google\AdsApi\Common\OAuth2TokenBuilder->validate() #1 C:\xampp\htdocs\seosystem\googleads-php-lib\examples\AdWords\v201809\BasicOperations\GetCampaigns.php(81): Google\AdsApi\Common\OAuth2TokenBuilder->build() #2 C:\xampp\htdocs\seosystem\googleads-php-lib\examples\AdWords\v201809\BasicOperations\GetCampaigns.php(90): Google\AdsApi\Examples\AdWords\v201809\BasicOperations\GetCampaigns::main() #3 C:\xampp\htdocs\seosystem\index.php(4): require_once('C:\\xampp\\htdocs...') #4 {main} thrown in C:\xampp\htdocs\seosystem\googleads-php-lib\src\Google\AdsApi\Common\OAuth2TokenBuilder.php on line 225 

I went to OAuth2TokenBuilder and replaced and still get the same Error Message no worries i'll change the key later

 private $clientId ='847786194979-n0udvkdi41r9fd5arlma6gadlm2kueot.apps.googleusercontent.com'; private $clientSecret ='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'; private $refreshToken ='Af8L57gifnGl1b4M324_Tg'; 

and this's the whole file

<?php /**  * Copyright 2016 Google Inc. All Rights Reserved.  *  * 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  *  *     http://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\AdsApi\Common; use Google\Auth\Credentials\ServiceAccountCredentials; use Google\Auth\Credentials\UserRefreshCredentials; use InvalidArgumentException; /**  * Builds OAuth2 access token fetchers.  *  * @see FetchAuthTokenInterface  */ final class OAuth2TokenBuilder implements AdsBuilder{     private $configurationLoader;     private $jsonKeyFilePath;     private $scopes;     private $impersonatedEmail;     private $clientId ='847786194979-n0udvkdi41r9fd5arlma6gadlm2kueot.apps.googleusercontent.com';     private $clientSecret ='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';     private $refreshToken ='Af8L57gifnGl1b4M324_Tg';     public function __construct(){         $this->configurationLoader = new ConfigurationLoader();     }     /**      * Reads configuration settings from the specified filepath. The filepath is      * optional, and if omitted, it will look for the default configuration      * filename in the home directory of the user running PHP.      *      * @see AdsBuilder::DEFAULT_CONFIGURATION_FILENAME      *      * @param string $path the filepath      * @return OAuth2TokenBuilder this builder populated from the configuration      * @throws InvalidArgumentException if the configuration file could not be      *     found      */     public function fromFile($path = null){         if ($path === null) {             $path = self::DEFAULT_CONFIGURATION_FILENAME;         }         return $this->from($this->configurationLoader->fromFile($path));     }     /**      * @see AdsBuilder::from()      */     public function from(Configuration $configuration){         $this->jsonKeyFilePath = $configuration->getConfiguration('jsonKeyFilePath', 'OAUTH2');         $this->scopes = $configuration->getConfiguration('scopes', 'OAUTH2');         $this->impersonatedEmail = $configuration->getConfiguration('impersonatedEmail', 'OAUTH2');         $this->clientId = $configuration->getConfiguration('clientId', 'OAUTH2');         $this->clientSecret = $configuration->getConfiguration('clientSecret', 'OAUTH2');         $this->refreshToken = $configuration->getConfiguration('refreshToken', 'OAUTH2');         return $this;     }     /**      * Includes an absolute path to an OAuth2 JSON key file when using service      * account flow. Required and only applicable when using service account flow.      *      * @param string|null $jsonKeyFilePath      * @return OAuth2TokenBuilder this builder      */     public function withJsonKeyFilePath($jsonKeyFilePath){         $this->jsonKeyFilePath = $jsonKeyFilePath;         return $this;     }     /**      * Includes OAuth2 scopes. Required and only applicable when using service      * account flow.      *      * @param string|null $scopes a space-delimited list of scopes      * @return OAuth2TokenBuilder this builder      */     public function withScopes($scopes){         $this->scopes = $scopes;         return $this;     }     /**      * Includes an email of account to impersonate when using service account      * flow. Optional and only applicable when using service account flow.      *      * @param string|null $impersonatedEmail      * @return OAuth2TokenBuilder this builder      */     public function withImpersonatedEmail($impersonatedEmail){         $this->impersonatedEmail = $impersonatedEmail;         return $this;     }     /**      * Includes an OAuth2 client ID. Required when using installed application or      * web application flow.      *      * @param string|null $clientId      * @return OAuth2TokenBuilder this builder      */     public function withClientId($clientId){         $this->clientId = $clientId;         return $this;     }     /**      * Includes an OAuth2 client secret. Required when using installed application      * or web application flow.      *      * @param string|null $clientSecret      * @return OAuth2TokenBuilder this builder      */     public function withClientSecret($clientSecret){         $this->clientSecret = $clientSecret;         return $this;     }     /**      * Includes an OAuth2 refresh token. Required when using installed application      * or web application flow.      *      * @param string|null $refreshToken      * @return OAuth2TokenBuilder this builder      */     public function withRefreshToken($refreshToken){         $this->refreshToken = $refreshToken;         return $this;     }     /**      * @see AdsBuilder::build()      */     public function build(){         $this->defaultOptionals();         $this->validate();         if ($this->jsonKeyFilePath !== null) {             return new ServiceAccountCredentials(                 $this->scopes,                 $this->jsonKeyFilePath,                 $this->impersonatedEmail             );         } else {             return new UserRefreshCredentials(                 null,                 [                     'client_id' => $this->clientId,                     'client_secret' => $this->clientSecret,                     'refresh_token' => $this->refreshToken                 ]             );         }     }     /**      * @see AdsBuilder::defaultOptionals()      */     public function defaultOptionals(){         // Nothing to default for this builder.     }     /**      * @see AdsBuilder::validate()      */     public function validate(){         if (($this->jsonKeyFilePath !== null || $this->scopes !== null)             && ($this->clientId !== null || $this->clientSecret !== null                 || $this->refreshToken !== null)) {             throw new InvalidArgumentException(                 'Cannot have both service account '                 . 'flow and installed/web application flow credential values set.'             );         }         if ($this->jsonKeyFilePath !== null || $this->scopes !== null) {             if ($this->jsonKeyFilePath === null || $this->scopes === null) {                 throw new InvalidArgumentException(                     'Both \'jsonKeyFilePath\' and '                     . '\'scopes\' must be set when using service account flow.'                 );             }         } elseif ($this->clientId === null             || $this->clientSecret === null             || $this->refreshToken === null) {             throw new InvalidArgumentException(                 'All of \'clientId\', '                 . '\'clientSecret\', and \'refreshToken\' must be set when using '                 . 'installed/web application flow.'             );         }     }     /**      * Gets the JSON key file path.      *      * @return string|null      */     public function getJsonKeyFilePath(){         return $this->jsonKeyFilePath;     }     /**      * Gets the scopes.      *      * @return string|null      */     public function getScopes(){         return $this->scopes;     }     /**      * Gets the impersonated email.      *      * @return string|null      */     public function getImpersonatedEmail(){         return $this->impersonatedEmail;     }     /**      * Gets the client ID.      *      * @return string|null      */     public function getClientId(){         return $this->clientId;     }     /**      * Gets the client secret.      *      * @return string|null      */     public function getClientSecret(){         return $this->clientSecret;     }     /**      * Gets the refresh token.      *      * @return string|null      */     public function getRefreshToken(){         return $this->refreshToken;     } } 

I recently got my new Macbook Pro and installed 3.8.6 with pyenv and created a virtualenv for my project. When I try to run the tests for this project i get the following error about a module not found by a dependency (abridged). The the files are all there, ad_manager is a file right next to the __init__.py file that is importing it. This was not a problem on my old machine.

echo $PYTHONPATH is empty

python -c 'import sys; print(sys.path)' -> ['', '/Users/derek/.pyenv/versions/3.8.6/lib/python38.zip', '/Users/derek/.pyenv/versions/3.8.6/lib/python3.8', '/Users/derek/.pyenv/versions/3.8.6/lib/python3.8/lib-dynload', '/Users/derek/.pyenv/versions/VIRTUAL_ENV_3.8.6/lib/python3.8/site-packages']

Traceback (most recent call last):   File "/Users/derek/dev/PATH_TO_PROJECT/tests/../src/services/adwords_service.py", line 18, in <module>     from googleads import oauth2, adwords   File "/Users/derek/.pyenv/versions/VIRTUAL_ENV_3.8.6/lib/python3.8/site-packages/googleads/__init__.py", line 17, in <module>     from ad_manager import AdManagerClient ModuleNotFoundError: No module named 'ad_manager' 

I figured out how to create & delete keyword plans, but I couldn't figure out how I can get a list of all my existing keyword plans (resource names / plan ids)?

final long customerId = Long.valueOf("XXXXXXXXXX");     GoogleAdsClient googleAdsClient = new ... KeywordPlanServiceClient client = googleAdsClient.getVersion8().createKeywordPlanServiceClient(); String[] allExistingKeywordPlans = client. ??? 


<dependency>     <groupId>com.google.api-ads</groupId>     <artifactId>google-ads</artifactId>     <version>16.0.0</version> </dependency> 


Further resources: https://developers.google.com/google-ads/api/docs/samples/add-keyword-plan

Any hints on how this can be solved is highly appreciated! Many thanks in advance!

We have a BigQuery data transfer of GoogleAds data. I came to realization, that I probably do not understand what is in the aggregates.

The discrepancy occurs with "Discovery" campaigns. Here is the query:

SELECT     '1. AdStats' as table,     SUM(Clicks)       AS clicks,     SUM(Cost)/1000000 AS cost,     SUM(Impressions)  AS impressions FROM `project.dataset.p_AdStats_*` WHERE Date = @date AND CampaignId = @campaign     UNION ALL SELECT     '2. AdBasicStats' as table,     SUM(Clicks)       AS clicks,     SUM(Cost)/1000000 AS cost,     SUM(Impressions)  AS impressions FROM `project.dataset.p_AdBasicStats_*` WHERE Date = @date AND CampaignId = @campaign     UNION ALL SELECT     '3. AdGroupStats' as table,     SUM(Clicks)       AS clicks,     SUM(Cost)/1000000 AS cost,     SUM(Impressions)  AS impressions FROM `project.dataset.p_AdGroupStats_*` WHERE Date = @date AND CampaignId = @campaign     UNION ALL SELECT     '4. AdGroupBasicStats' as table,     SUM(Clicks)       AS clicks,     SUM(Cost)/1000000 AS cost,     SUM(Impressions)  AS impressions FROM `project.dataset.p_AdGroupBasicStats_*` WHERE Date = @date AND CampaignId = @campaign ORDER BY 1 

The results come in:

table                clicks cost       impressions 1. AdStats           74     2.906935   15582 2. AdBasicStats      74     345.444868 15582 3. AdGroupStats      78     15.786935  15802 4. AdGroupBasicStats 78     358.324868 15802 

The GoogleAds UI shows 78 clicks, €358.32 and 15802 impressions for campaign report. It matches AdGroupBasicStats.

But I need more.. I need math to hold - AdBasicStats should have the same data, but in more granular detail (on Ad level). But it does not. Also, this is just killing me:

345.444868 + 15.786935 - 2.906935 = 358.324868 ?!?! 

What the actual f...? I've tested multiple days, different campaigns. The math is there. Can someone explain me what does those aggregates have? Point me to any resource describing the data in the tables, please.

Couple of notes:

  1. I suspect that data from AdStats is already in both AdBasicStats and AdGroupStats. Thus the minus in equation. But what does that data stand for? How can I identify such data in other aggregates?
  2. Backfill is not the culprit, I've refreshed data multiple times in historical periods.
  3. Interestingly enough, this behaviour only occurs with "Discovery" campaigns. Other types, e.g. "Display", seems not to have this discrepancy.
  4. I've tried to contact Google Ads support, but they directed me to the GCP support instead, which we don't have available for our account.