首页 > 解决方案 > PHP Google Adwords API 获取广告系列

问题描述

我正在使用 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 服务?

标签: oauthgoogle-apigoogle-ads-apigoogle-api-php-client

解决方案


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

$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


推荐阅读