require_once dirname(__FILE__).'/google-api-php-client/Google_Client.php'; require_once dirname(__FILE__).'/google-api-php-client/contrib/Google_AdSenseService.php'; require_once dirname(__FILE__).'/google-api-php-client/contrib/Google_Oauth2Service.php'; $SERVICE_ACCOUNT_PKCS12_FILE_PATH = dirname(__FILE__).'/keyfile.p12'; // create client object and set app name $client = new Google_Client(); $client->setApplicationName("XXXX"); // name of your app // set assertion credentials $key = file_get_contents($SERVICE_ACCOUNT_PKCS12_FILE_PATH); $auth = new Google_AssertionCredentials( "YYY...@developer.gserviceaccount.com", // email you added to GA array('https://www.googleapis.com/auth/adsense.readonly'), $key); $client->setAssertionCredentials($auth); $client->getAuth()->refreshTokenWithAssertion(); $accessToken = $client->getAccessToken(); // other settings $client->setClientId("XYZ.apps.googleusercontent.com"); // from API console $service = new Google_AdsenseService($client); $optParams = array('metric' => array('earnings'), 'dimension' => 'date'); $data = $service -> reports -> generate('2013-01-01', '2013-03-03', $optParams);
(403) User does not have an AdSense account
But I got the error messege :
Please help me!!
Using a Refresh Token
As indicated in the previous section, a refresh token is obtained in offline scenarios during the first authorization code exchange. In these cases, your application may obtain a new access token by sending a refresh token to the Google OAuth 2.0 Authorization server.
To obtain a new access token this way, your application performs an HTTPs POST to https://accounts.google.com/o/oauth2/token. The request must include the following parameters...
tried creating DB (examples.sqlite and table auth) but then I get different errors
General error: 26 file is encrypted or is not a database
result = Jose.investigate()
print result
>>> Done!
Thank you!
Thank you!
Thank you!
<CTRL><C>
KeyboardInterrupt
>>> _
In PHP 5.1, the SQLite extension also provides a driver for SQLite 2 databases; while it is not technically a part of the PDO_SQLITE driver, it behaves similarly, so it is documented alongside it. The SQLite 2 driver for PDO is provided primarily to make it easier to import legacy SQLite 2 database files into an application that uses the faster, more efficient SQLite 3 driver. As a result, the SQLite 2 driver is not as feature-rich as the SQLite 3 driver.
php 5.3.10
sqlite 2.8.17
Jose,
thanks for all your support.
I succed in connect and use api by access token manually....