我正在尝试使用谷歌广告 PHP SDK 连接到谷歌广告 API。我按照说明操作,并成功启动了 GoogleAdsServiceClient,但是当我尝试使用搜索方法时,它崩溃了,只说“invalid_grant”,而没有关于如何从错误中恢复的说明。有没有人知道如何调试或解决这个问题?
我收到的错误消息。
Client error: `POST https://oauth2.googleapis.com/token` resulted in a `400 Bad Request` response:
{
"error": "invalid_grant",
"error_description": "Bad Request"
}
错误发生在
/vendor/googleads/google-ads-php/src/Google/Ads/GoogleAds/V7/Services/Gapic/GoogleAdsServiceGapicClient.php -> getPagedListResponse(第 457 行)
return $this->getPagedListResponse('Search', $optionalArgs, SearchGoogleAdsResponse::class, $request);
我美丽的代码
$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);
}