【问题标题】:'Google AdSense API' PHP sample code is not working“Google AdSense API”PHP 示例代码不起作用
【发布时间】:2017-04-21 20:52:32
【问题描述】:

请帮帮我....

我想使用 Google AdSense API 通过 PHP 获得收入。

但是示例代码不起作用。

  1. PUTTY - SSH connect

  2. Install 'Composer'

    php -r "if (hash_file('SHA384', 'composer-setup.php') === 'aa96f26c2b67226a324c27919f1eb05f21c248b987e6195cad9690d5c1ff713d53020a02ac8c217dbf90a7eacc9d141d') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

    php composer-setup.php

    php -r "unlink('composer-setup.php');"

  3. 安装“用于 PHP 的 Google API 客户端库”

    php composer.phar 需要 google/apiclient:^2.0

  4. 将适用于 PHP 的 AdSense Management API 示例复制到您的服务器。

    https://github.com/googleads/googleads-adsense-examples/tree/master/php-clientlib-1.x/v1.x

  5. 修改client_secrets.json

客户端 ID、客户端密码和重定向 URL

  1. 在浏览器中打开示例。示例代码但不起作用

......T_T

  1. 我在两周内尝试了许多不同的方法

我的猜测是路径有问题。但那是错误的。

[adsense-sample.php - 之前]

/************************************************

  ATTENTION: Change this path to point to your

  client library installation!

 ************************************************/

set_include_path('/path/to/clientlib' . PATH_SEPARATOR . get_include_path());

require_once 'Google/Client.php';

require_once 'Google/Service/AdSense.php';

// Autoload example classes.

function __autoload($class_name) {

  include 'examples/' . $class_name . '.php';

}

[adsense-sample.php - 之后]

require_once __DIR__.'/vendor/autoload.php';

require_once 'templates/base.php';

require_once 'examples/CollateReportData.php';

require_once 'examples/FillMissingDatesInReport.php';

require_once 'examples/GenerateReport.php';

require_once 'examples/GenerateReportWithPaging.php';

require_once 'examples/GenerateSavedReport.php';

require_once 'examples/GetAccountTree.php';

require_once 'examples/GetAllAccounts.php';

require_once 'examples/GetAllAdClients.php';

require_once 'examples/GetAllAdUnits.php';

require_once 'examples/GetAllAdUnitsForCustomChannel.php';

require_once 'examples/GetAllAlerts.php';

require_once 'examples/GetAllCustomChannels.php';

require_once 'examples/GetAllCustomChannelsForAdUnit.php';

require_once 'examples/GetAllDimensions.php';

require_once 'examples/GetAllMetrics.php';

require_once 'examples/GetAllSavedAdStyles.php';

require_once 'examples/GetAllSavedReports.php';

require_once 'examples/GetAllUrlChannels.php';

请帮帮我...

【问题讨论】:

  • 有任何错误、警告或类似的东西吗?

标签: php adsense-api


【解决方案1】:

确保您已将 adsense-sample.php 文件的路径放在 API 管理器控制台的凭据部分。您必须添加“yoursite.com/adsense-sample.php”;作为授权的重定向 URI。这也必须作为 URI 添加到 client_secrets.json 中

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-19
    • 2020-12-17
    • 1970-01-01
    • 1970-01-01
    • 2012-12-28
    • 2013-09-20
    • 1970-01-01
    相关资源
    最近更新 更多