2

Please, Help me....

I would like to use the Google AdSense API to get my Earnings through PHP.

But sample code is not working.

  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. Install 'Google APIs Client Library for PHP'

    php composer.phar require google/apiclient:^2.0

  4. Copy the AdSense Management API sample for PHP to your server.

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

    [Show FTP image]

  5. Modify client_secrets.json

client ID, client secret and redirect URL

  1. Open the sample in browser. Sample code is But not working

......T_T

  1. I tried many different ways while two weeks

My guess is that the path is a problem. But that is wrong to that.

[adsense-sample.php - Before]

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

  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 - After]

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

Please, help me...

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Heeman Seo
  • 21
  • 2

1 Answers1

0

Make sure you have put the path to your adsense-sample.php file in the credentials section of the API manager console. You will have to add 'yoursite.com/adsense-sample.php'; as an authorized redirect URI. This also has to be added as the URI in the client_secrets.json

mark_3094
  • 659
  • 4
  • 11