I'm trying to use the google ads PHP SDK to connect to the Google ads API. I'v followed the instructions, and successfully initiate the GoogleAdsServiceClient, but when I try to use the search method, it crashes saying only "invalid_grant" and no instructions on how to recover from the error. Does anyone have an idea on how to debug or get past this?
The error message I get.
Client error: `POST https://oauth2.googleapis.com/token` resulted in a `400 Bad Request` response:
{
"error": "invalid_grant",
"error_description": "Bad Request"
}
Error occurs at
/vendor/googleads/google-ads-php/src/Google/Ads/GoogleAds/V7/Services/Gapic/GoogleAdsServiceGapicClient.php -> getPagedListResponse (line 457)
return $this->getPagedListResponse('Search', $optionalArgs, SearchGoogleAdsResponse::class, $request);
My beautiful code
$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile(realpath(base_path('google_ads_php.ini')))->build();
$api = (new GoogleAdsClientBuilder())
->fromFile(realpath(base_path('google_ads_php.ini')))
->withOAuth2Credential($oAuth2Credential)
->build();
$serviceClient = $api->getGoogleAdsServiceClient();
$query = 'SELECT campaign.id, campaign.name FROM campaign ORDER BY campaign.id';
//this is were it crashes and returns 400
$stream = $serviceClient->search($this->customerId, $query);
foreach ($stream->iterateAllElements() as $googleAdsRow) {
dd($googleAdsRow);
}