So I'm utilizing v23 of the googleads/google-ads-php.
I have all my credentials setup, and everything is working correctly.
I can confirm this by manually posting to the /token endpoint, and get an access token. However, utilizing the SDK I get "{ "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https:\/\/
developers.google.com\/identity\/sign-in\/web\/devconsole-project.", "code": 16, "status": "UNAUTHENTICATED", "details": [ { "@type": "
type.googleapis.com\/google.ads.googleads.v16.errors.GoogleAdsFailure", "errors": [ { "errorCode": { "authenticationError": "OAUTH_TOKEN_HEADER_INVALID" }, "message": "Oauth token HTTP header is malformed." } ], "requestId": "k4fKAZ34qnUykl_MdjuIWw" } ] }"
It appears as though the access token is not being automatically generated.
Here is my code for getting the GoogleAdsClient object:
public static function getGoogleAdsClient(): GoogleAdsClient
{
$oAuth2Credential = (new OAuth2TokenBuilder())
->withClientId(config('google-ads.client_id'))
->withClientSecret(config('google-ads.client_secret'))
->withRefreshToken(config('google-ads.refresh_token'))
->build();
return (new GoogleAdsClientBuilder())
->withOAuth2Credential($oAuth2Credential)
->withDeveloperToken(config('google-ads.developer_token'))
->usingGapicV2Source(true)
->build();
}
And then my quick test:
$client = App\Libraries\Google\Ads::getGoogleAdsClient();
$googleAdsServiceClient = $client->getGoogleAdsServiceClient();
$query = 'SELECT
campaign.id,
campaign.name FROM campaign ORDER BY
campaign.id';
$stream = $googleAdsServiceClient->searchStream(
SearchGoogleAdsStreamRequest::build(config('google-ads.customer_id'), $query)
);
foreach ($stream->iterateAllElements() as $googleAdsRow) {
printf(
"Campaign with ID %d and name '%s' was found.%s",
$googleAdsRow->getCampaign()->getId(),
$googleAdsRow->getCampaign()->getName(),
PHP_EOL
);
}
Any help would be appreciated because I'm tearing my hair out trying to get this to work.