【发布时间】:2021-03-23 12:30:18
【问题描述】:
我正在开发一个与 Google Ads 集成的应用程序,并将广告/广告系列等数据同步到我的服务器中。当我尝试从 Google Ads API 请求一些数据时,我收到了与授权相关的错误。这是我现在完成的步骤:
- 在验证 OAuth 应用程序和范围方面向 Google 申请(完成,我们从 Google 获得了验证,可以要求 AdWords 范围)
- 向 Google Ads 申请获取开发者令牌并得到它。 (基本访问)
- 我们能够连接测试帐户并成功获得响应。但是当我们使用真实账户尝试时,我们会收到以下错误。
代码也来自原始的 Google Ads API 示例。我尝试过大量不同的帐户,但似乎没有一个有效。当我尝试从 AdWords API 而不是 Google Ads API 获取具有相同参数的这些数据时,它可以工作。但是 Google AdWords PHP SDK 不再维护,所以我必须继续尝试使用 Google Ads API。我在下面分享我的代码:
{
$this->customerId = $customerId;
$this->clientId = $clientId;
$this->clientSecret = $clientSecret;
$this->accessToken = $accessToken;
$oAuth2Credential = (new OAuth2TokenBuilder())
->withClientId($this->clientId)
->withClientSecret($this->clientSecret)
->withRefreshToken($this->accessToken)
->build();
$this->googleAdsClient = (new GoogleAdsClientBuilder())
->withOAuth2Credential($oAuth2Credential)
->withDeveloperToken(env("GOOGLE_DEVELOPER_TOKEN"))
->withLoginCustomerId((int) $this->customerId)
->build();
}
public function getCampaigns(): array
{
try {
$campaigns = [];
$services = $this->googleAdsClient->getGoogleAdsServiceClient();
$results = $services->search($this->customerId, $this->campaignQuery(), ['pageSize' => self::PAGE_SIZE]);
foreach ($results->iterateAllElements() as $row) {
$campaigns[] = (new Campaign())->transform($row);
}
return $campaigns;
} catch (GoogleAdsException $googleAdsException) {
// TODO add error log
return [];
}
}```
The error:
```Google\ApiCore\ApiException: {
"message": "The caller does not have permission",
"code": 7,
"status": "PERMISSION_DENIED",
"details": [
{
"@type": 0,
"data": "type.googleapis.com\/google.ads.googleads.v6.errors.GoogleAdsFailure"
},
{
"@type": 0,
"data": [
{
"errorCode": {
"authorizationError": "DEVELOPER_TOKEN_PROHIBITED"
},
"message": "Developer token is not allowed with project '691752477594'."
}
]
}
]}```
【问题讨论】:
标签: php google-ads-api