【问题标题】:Google Ads Api Developer Token Error - even though it is validatedGoogle Ads Api 开发人员令牌错误 - 即使已验证
【发布时间】: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


    【解决方案1】:

    您是否使用与 API 调用相同的云控制台项目凭据登录您的站点?

    对 Google Ads API 的首次调用会将开发者令牌永久关联到云项目。如果这与您在网站上使用的不同,您可能需要切换它们。

    【讨论】:

      【解决方案2】:

      一些开发者令牌已经与您正在尝试的项目相关联, 要解决此问题,您必须在控制台中再创建一个 App 项目并重新配置您的 secrate 密钥,并使用您创建的新项目的客户端 ID 不要忘记使用最新的开发人员令牌,即(您当前的开发人员令牌)并制作第一个 API调用,那么您的开发者令牌将永远配对,一旦绑定,以后将永远不会更改。

      【讨论】:

        猜你喜欢
        • 2016-06-18
        • 2015-09-11
        • 2011-09-11
        • 1970-01-01
        • 2020-11-18
        • 1970-01-01
        • 2018-04-25
        • 1970-01-01
        • 2021-10-24
        相关资源
        最近更新 更多