代码之家  ›  专栏  ›  技术社区  ›  nnikolay

PHP谷歌广告词API获取活动

  •  0
  • nnikolay  · 技术社区  · 8 年前

    我正在使用谷歌adwords API连接adwords并列出所有的campaingns。我正在与OAuth连接到Adwords帐户,并成为一个access_令牌和一个refresh_令牌,我正在将其保存到DB中。

    现在我想举个例子: https://github.com/googleads/googleads-php-lib/blob/master/examples/AdWords/v201802/BasicOperations/GetCampaigns.php

    但是我的access_令牌和refresh_令牌在数据库中,所有API OAuth2凭据都在一个配置数组中。

    如何使用此凭据查询谷歌adwords服务?

    1 回复  |  直到 8 年前
        1
  •  1
  •   Peter Bowen    8 年前

    下面复制的示例第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();
    

    以下是谷歌AdWords API其他一些问题的概述: https://pete-bowen.com/how-to-use-the-google-adwords-api-to-automate-adwords