Google ads API PHP 无法运行文档示例

问题描述 投票:0回答:1

我正在运行 symfony 6 服务器/php 8.0.8,google ads api V22.0.0。获得了开发令牌/刷新令牌以及所有其他信息,并且无法运行来自谷歌的简单示例,我不确定我做错了什么。这是我的代码:

use Google\Ads\GoogleAds\Lib\V14\GoogleAdsClientBuilder;
use Google\Ads\GoogleAds\Lib\OAuth2TokenBuilder;
use Google\Ads\GoogleAds\V14\Services\GoogleAdsServiceClient;
use Google\Ads\GoogleAds\V14\Services\SearchGoogleAdsStreamRequest;

    $developerToken = 'xxxx';  
    $clientId = 'yyyy';
    $clientSecret = 'zzzz';
    $refreshToken = 'dddd'; 
    $loginCustomerId = 'vvvv';  
    
    try {
        $oAuth2Credential = (new OAuth2TokenBuilder())
            ->withClientId($clientId)
            ->withClientSecret($clientSecret)
            ->withRefreshToken($refreshToken)
            ->build();

        $googleAdsClient = (new GoogleAdsClientBuilder())
            ->withDeveloperToken($developerToken)
            ->withOAuth2Credential($oAuth2Credential)
            ->withLoginCustomerId($loginCustomerId)
            ->build();

        $googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();
        
        $query = 'SELECT campaign.id, campaign.name FROM campaign ORDER BY campaign.id';
        

        $stream2 = $googleAdsServiceClient->searchStream($loginCustomerId, $query
        );          
       foreach ($stream2->iterateAllElements() as $googleAdsRow) {
           not reaching this
       }
    }
     catch (\Google\ApiCore\ApiException $e) {
        // Gérer les erreurs
        $this->_logCall(self::LOG_GOOGLE_ADS, 'ERREUR:',$e->getBasicMessage());
    }       

这是错误:

错误 404(未找到)!!1

在此服务器上找不到所请求的 URL

/v14/customers/vvvv/googleAds:searchStream
。 这就是我们所知道的。

任何帮助将非常感激

php symfony google-ads-api
1个回答
0
投票

使用 V14 不行,我能够将 google ads api 从 22.0.0 更新到 22.1.0,这样做可以让我访问 V16。唯一的问题是使用 MCC id 实例化 googleAdsClient,然后使用客户端 id 实例化 searchStream

© www.soinside.com 2019 - 2024. All rights reserved.