我正在使用谷歌adwords API连接adwords并列出所有活动 . 我正在将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服务?
在您的示例的第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
1 回答
在您的示例的第81行中引用并在下面复制的OAuth2TokenBuilder类有几种方法可以让您设置参数而不是从配置文件中读取它们 .
fromFile方法将从配置文件中读取参数 . 您的新代码可能如下所示:
Google AdWords API的其他一些问题的高级概述:https://pete-bowen.com/how-to-use-the-google-adwords-api-to-automate-adwords