Re: PHP empty reports results

55 views
Skip to first unread message

Sérgio Gomes (AdSense API Team)

unread,
Apr 9, 2013, 12:44:52 PM4/9/13
to adsen...@googlegroups.com
Hi Renato,

I can't find anything immediately wrong with your code, but I might be missing something.

Could you send a message to adsense...@google.com with your request and response HTTP logs? That should help us track down the issue.

Thanks!

Cheers,
Sérgio

---
Sérgio Gomes
Developer Relations

Google UK Limited
Registered Office: Belgrave House, 76 Buckingham Palace Road, London SW1W 9TQ
Registered in England Number: 3977902


On Wednesday, 3 April 2013 20:33:41 UTC+1, Renato Valencia wrote:
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.


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

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

Reply all
Reply to author
Forward
0 new messages