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());
}
Ive got the refreshToken
from buildFullAuthorizationUri() that prompted google login screen correctly.
: Uncaught InvalidArgumentException: OAuth2 authentication credentials must not be null.
Any ideas on how to solve that? File paths are correct because I can print those files content.