yes, its funny because the code i am using have your copyright :P
/**
* Include the library files for the api client and AdSense service
class.
*/
require_once "google-api-php-client/src/apiClient.php";
require_once "google-api-php-client/src/contrib/
apiAdsenseService.php";
/**
* Handles authentication and OAuth token storing.
* Assumes the presence of a sqlite database called './
examples.sqlite'
* containing a table called 'auth' composed of two VARCHAR(255)
fields called
* 'user' and 'token'.
*
* @author Silvano Luciani <
silvano...@gmail.com>
*/
class AdSenseAuth {
protected $apiClient;
protected $adSenseService;
private $user;
/**
* Create the dependencies.
* (Inject them in a real world app!!)
*/
public function __construct() {
// Create the apiClient instances.
$this->apiClient = new apiClient();
// Visit
https://code.google.com/apis/console?api=adsense to
// generate your oauth2_client_id, oauth2_client_secret, and to
// register your oauth2_redirect_uri.
$this->apiClient->setClientId('#################');
$this->apiClient->setClientSecret('##################');
$this->apiClient->setDeveloperKey('###################');
// Point the oauth2_redirect_uri to index.php.
$this->apiClient->setRedirectUri('
http://myurl.com/tests/
adsense_auth.php?logged');
// Create the api AdsenseService instance.
$this->adSenseService = new apiAdsenseService($this->apiClient);
}
/**
* Check if a token for the user is already in the db, otherwise
perform
* authentication.
* @param string $user The user to authenticate
*/
public function authenticate($user) {
$this->user = $user;
// Override the scope to use the readonly one
$this->apiClient->setScopes(
array("
https://www.googleapis.com/auth/adsense.readonly"));
// Go get the token
$this->apiClient->setAccessToken($this->apiClient-
>authenticate());
}
/**
* Return the AdsenseService instance (to be used to retrieve data).
* @return apiAdsenseService the authenticated apiAdsenseService
instance
*/
public function getAdSenseService() {
return $this->adSenseService;
}
public function getToken() {
return $this->apiClient->getAccessToken();
}
}
$client = new AdSenseAuth();
$client->authenticate("john");
if(isset($_GET["logged"])){
echo $client->getToken();