'Google AdSense API' sample code is not working

183 views
Skip to first unread message

HeeMan Seo

unread,
Dec 6, 2016, 7:46:41 PM12/6/16
to Google APIs Explorer Users Forum



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 "copy('https://getcomposer.org/installer', 'composer-setup.php');"

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




5. Modify client_secrets.json

client ID, client secret and redirect URL


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

......T_T




7. 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...


Thank you.




HeeMan Seo

unread,
Dec 6, 2016, 7:47:49 PM12/6/16
to Google APIs Explorer Users Forum

John Boswell

unread,
Dec 6, 2016, 8:23:58 PM12/6/16
to Google APIs Explorer Users Forum
I don't see where you import the client library in "adsense-sample.php - After". But I don't know much about this API, so maybe I'm missing it.

You might have better luck asking their support specifically, rather than this APIs Explorer group.
Reply all
Reply to author
Forward
0 new messages