2

私を助けてください....

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

    [FTP画像を表示]

  5. client_secrets.json を変更する

クライアント ID、クライアント シークレット、およびリダイレクト URL

  1. サンプルをブラウザーで開きます。サンプルコードはしかし、動作していません

……T_T

  1. 私は2週間の間、さまざまな方法を試しました

私の推測では、パスが問題です。しかし、それは間違っています。

[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';

}

↓</p>

[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';

私を助けてください...

4

1 に答える 1

0

API マネージャー コンソールの認証情報セクションに、adsense-sample.php ファイルへのパスを入力したことを確認してください。「yoursite.com/adsense-sample.php」を追加する必要があります。承認されたリダイレクト URI として。これも client_secrets.json の URI として追加する必要があります。

于 2016-12-09T02:05:36.603 に答える