PHP Google Adwords API 获取广告系列

PHP Google Adwords API get campaigns

我正在使用 google adwords API 来连接 adwords 并列出所有的 campaingns。我正在使用 OAuth 连接到 Adwords 帐户,并成为 access_token 和 refresh_token,我正在将其保存到数据库中。

现在我正在尝试做这个例子: https://github.com/googleads/googleads-php-lib/blob/master/examples/AdWords/v201802/BasicOperations/GetCampaigns.php

但是我的 access_token 和 refresh_token 在数据库中,所有 API OAuth2 凭据都在一个配置数组中。

如何使用此凭据查询 hte google adwords 服务?

OAuth2TokenBuilder class 在您的示例的第 81 行中引用并在下面复制有几种方法可以让您设置参数而不是从配置文件中读取它们。

$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build();

fromFile 方法将从配置文件中读取参数。您的新代码可能如下所示:

$oAuth2Credential = (new OAuth2TokenBuilder())
        ->withClientId(your oauth2 client id here)
        ->withClientSecret(your oauth2 client secret here)
        ->withRefreshToken(your stored refresh token here)
        ->build();

Google AdWords API 的其他一些问题的高级概述: https://pete-bowen.com/how-to-use-the-google-adwords-api-to-automate-adwords