Group: http://groups.google.com/group/adsense-api/topics
- PHP empty reports results [1 Update]
- Renato Valencia <renatovalencia@gmail.com> Apr 03 12:33PM -0700
Hello guys hope someone can help me.
So I manage to authenticate using the examples of the client library and by
my own script and both are giving me empty results.
But when I use the google site "try it
yourself": https://developers.google.com/adsense/management/v1.2/reference/reports/generate#try-it
It does give me some results.
Tnx a lot!
* Some screenshots attached and my own script code here:
<?php
session_start();
require_once 'src/Google_Client.php';
require_once 'src/contrib/Google_AdsenseService.php';
$client = new Google_Client();
$client -> setApplicationName('Ad Sense Revenue');
$client -> setClientId('#clientid');
$client -> setClientSecret('#clientsecret');
$client -> setRedirectUri('http://localhost/test/index.php');
$client -> setDeveloperKey('#apikey');
$client -> setScopes('https://www.googleapis.com/auth/adsense
https://www.googleapis.com/auth/adsense.readonly');
$service = new Google_AdSenseService($client);
if (isset($_GET['logout'])) { // logout: destroy token
unset($_SESSION['token']);
die('Logged out.');
}
if (isset($_GET['code'])) { // we received the positive auth callback, get
the token and store it in session
$client->authenticate();
$_SESSION['token'] = $client->getAccessToken();
}
if (isset($_SESSION['token'])) { // extract token from session and
configure client
$token = $_SESSION['token'];
$client->setAccessToken($token);
}
if (!$client->getAccessToken()) { // auth call to google
$authUrl = $client->createAuthUrl();
header("Location: ".$authUrl);
die;
}
try {
$optParams = array('metric' => array('earnings'), 'dimension' => 'date');
$data = $service -> reports -> generate('2013-01-01', '2013-03-03',
$optParams);
echo '<pre>' . print_r($data, TRUE) . '</pre>';
} catch(Exception $e) {
echo '<pre>', print_r($e, TRUE) . '</pre>';
}
You received this message because you are subscribed to the Google Group adsense-api.
You can post via email.
To unsubscribe from this group, send an empty message.
For more options, visit this group.
You received this message because you are subscribed to the Google Groups "AdSense API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adsense-api+unsubscribe@googlegroups.com.
To post to this group, send email to adsense-api@googlegroups.com.
Visit this group at http://groups.google.com/group/adsense-api?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Helping optimistic people excel - in 7 areas of life is her mission.
ReplyDeleteYou have to find a way to take the tips you learn and make maximum use of
them. Remember; there is a difference between a fattening diet and a healthy diet.
Feel free to visit my blog post fitness tips and workouts