Google广告API PHP
我正在尝试使用服务帐户与Google ADS API连接。
在Momet上,我的代码看起来像这样:
$oAuth2Credential = (new OAuth2TokenBuilder())
->withJsonKeyFilePath(self::CREDENTIALS_FILE_PATH)
->withScopes('https://www.googleapis.com/auth/adwords')
->withImpersonatedEmail(IMPERSONATED_EMAIL)
->build();
$googleAdsClient = (new GoogleAdsClientBuilder())
->withOAuth2Credential($oAuth2Credential)
->withDeveloperToken(DEVELOPER_TOKEN)
->build();
$googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();
$query = 'SELECT campaign.id, campaign.name FROM campaign ORDER BY campaign.id';
$stream =
$googleAdsServiceClient->searchStream(CUSTOMER_ID, $query);
在Google Cloud中,我创建了一个项目和一个服务帐户。该帐户与我可以在Google广告中访问的帐户相同。另外,我还在Google Workspace设置了整个领域的代表团,并拥有相同的帐户。我认为我做对了,但是我遇到了这个错误:
我希望有人可以帮助我。
I am trying to use a service account to connect with the Google Ads API.
At the momet my code looks like this:
$oAuth2Credential = (new OAuth2TokenBuilder())
->withJsonKeyFilePath(self::CREDENTIALS_FILE_PATH)
->withScopes('https://www.googleapis.com/auth/adwords')
->withImpersonatedEmail(IMPERSONATED_EMAIL)
->build();
$googleAdsClient = (new GoogleAdsClientBuilder())
->withOAuth2Credential($oAuth2Credential)
->withDeveloperToken(DEVELOPER_TOKEN)
->build();
$googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();
$query = 'SELECT campaign.id, campaign.name FROM campaign ORDER BY campaign.id';
$stream =
$googleAdsServiceClient->searchStream(CUSTOMER_ID, $query);
In Google cloud I have created a project and a service account. The account is the same I have access to at Google Ads. Also I have set the Domain-Wide Delegation at Google Workspace, with this same account. In my opinion I did everything right, but I am getting this error:
I hope there's someone who can help me out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
HY JOL123,Google中的服务帐户更像是普通的用户帐户。因此,要使普通用户访问您的广告帐户,您必须与用户共享对该帐户的访问权限(使用用户的电子邮件地址)。
服务帐户必须做同样的事情。您必须进入您希望访问和共享访问权限的Google Ads帐户的服务帐户“电子邮件”。
Hy jol123, Service accounts in Google are more like normal user accounts. So for a normal user to access your Ads account, you would have to share access to that account with the user(using the user's email address).
The same thing has to be done for the service account. You have to go into the Google ads account you wish to access and share access with the service account "email" you are using.