Hello,
Im trying to write a PHP script to check historical data of avg monthly
searches for a given keywords list. However I cannot get the credential
files to work.
// planner.php
use Google\Ads\GoogleAds\Lib\V18\GoogleAdsClientBuilder;
use Google\Ads\GoogleAds\V18\Services\
GenerateKeywordHistoricalMetricsRequest;
require 'vendor/autoload.php';
$configFilePath = 'google_ads_php.ini';
$googleAdsClient = (new GoogleAdsClientBuilder())
->fromFile($configFilePath)
->build();
$customerId = '9810123038';
try {
$keywordPlanService = $googleAdsClient->getKeywordPlanIdeaServiceClient
();
$keywords = ['test keyword', 'another keyword'];
$request = new GenerateKeywordHistoricalMetricsRequest([
'keywords' => $keywords
]);
$response = $keywordPlanService->generateKeywordHistoricalMetrics(
$request);
foreach ($response->getMetrics() as $metric) {
printf(
"Keyword: %s, Avg monthly volume: %d\n",
$metric->getText(),
$metric->getMetrics()->getAvgMonthlySearches()
);
}
} catch (Exception $e) {
printf("Error: %s\n", $e->getMessage());
}
in the same folder as code above I have 2 files:
// google_ads_php.ini
[GOOGLE_ADS]
developerToken = "cut"
jsonKeyFilePath = "E:/path/to/credentials.json"
scopes = "https://www.googleapis.com/auth/adwords"
clientId = "clientid.apps.googleusercontent.com"
clientSecret = "cut"
refreshToken = "cut"
Ive got the refreshToken from buildFullAuthorizationUri() that prompted
google login screen correctly.
and:
// credentials.json
{"web":
{"client_id":"cut",
"project_id":"cut",
"auth_uri":"https://accounts.google.com/o/oauth2/auth",
"token_uri":"https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs",
"client_secret":"cut",
"redirect_uris":["http://localhost"]}}
No matter what I do I cannot go over:
*Fatal error*: Uncaught InvalidArgumentException: OAuth2 authentication
credentials must not be null.
Stack trace: #0
Google\Ads\GoogleAds\Lib\V18\GoogleAdsClientBuilder->validate()
Google\Ads\GoogleAds\Lib\V18\GoogleAdsClientBuilder->build()
thrown in
*google-ads-php\src\Google\Ads\GoogleAds\Lib\V18\GoogleAdsClientBuilder.php*
on line *429*
Any ideas on how to solve that? File paths are correct because I can print
those files content.
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups
"Google Ads API and AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/adwords-api/5fc12b6f-a096-4d21-91ae-c28b239fd0e3n%40googlegroups.com.