Hi,

I am trying to fetch google Analytics data using following example but no result.

I am getting error

Code:
( ! ) Fatal error: Uncaught exception 'Exception' with message ' in C:\wamp\www\gapi\gapi.class.php on line 92
( ! ) Exception: GAPI: Failed to request account data. Error: " Error 404 (Not Found)!!1 *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/errors/logo_sm_2.png) no-repeat}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/errors/logo_sm_2_hr.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/errors/logo_sm_2_hr.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/errors/logo_sm_2_hr.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:55px;width:150px} 404. That’s an error. The requested URL /analytics/feeds/accounts/default?start-index=1&max-results=20 was not found on this server. That’s all we know. " in C:\wamp\www\gapi\gapi.class.php on line 92

PHP Code:
<?php
  
require 'gapi.class.php';

 
$gaEmail 'youremail@email.com';
 
$gaPassword 'your password';
 
$profileId 'your profile id';

 
$dimensions = array('pagePath','country''region''city'); 
 
$metrics = array('visits');
 
$sortMetric=null;
 
$filter=null;
 
$startDate='2011-02-01';
 
$endDate='2011-02-28';
 
$startIndex=1;
 
$maxResults=10000;

 
$ga = new gapi($gaEmail$gaPassword);

$ga->requestReportData($profileId$dimensions$metrics$sortMetric$filter,        $startDate$endDate$startIndex$maxResults);

 
$totalPageviews $ga->getPageviews();

 foreach (
$ga->getResults() as $result) {
    
$visits $result->getVists();
    print 
$visits
  }

 
?>

PHP Code:
<?php
    define
('ga_email','you email');
    
define('ga_password','passworkd');
    
define('ga_profile_id','profile ID or View ID');

    require 
'gapi.class.php';

    
// pars to pass on Google Server Analytic Api

    
$start_date='2013-12-01';
    
$end_date='2013-12-31';

    
$ga = new gapi(ga_email,ga_password);

    try {

      
$ga->requestReportData(ga_profile_id,
      array(
'browser','browserVersion'),
      array(
'pageviews','visits','visitors','visitBounceRate'),
      
$sort_metric=null$filter=null,
      
$start_date,$end_date,
      
$start_index=1$max_results=30);

    } catch (
Exception $e) {
        echo 
'Caught exception: ',  $e->getMessage(), "\n";
    }

    
?>
    <table width='60%'>
    <tr style="background-color:#00ff00;">
      <th>Browser &amp; Browser Version</th>
      <th>Page Views</th>
      <th>Visits</th>
      <th>Visitors</th>
      <th>Visit Bounce Rate</th>

    </tr>
    <?php
    $i 
0;
    foreach(
$ga->getResults() as $result):
      
//$ga->printfs($result);
      
if($i%== 0$color "#d3d3d3";
      else 
$color "#FFFFF";
    
?>
    <tr style="background-color:<?php echo $color ?>">
      <td><?php echo $result ?></td>
      <td><?php echo $result->getPageviews() ?></td>
      <td><?php echo $result->getVisits() ?></td>
      <td><?php echo $result->getVisitors() ?></td>
      <td><?php echo $result->getVisitBounceRate() ?></td>

    </tr>
    <?php
    $i
++;
    endforeach
    
?>
    </table>

    <table>
    <tr>
      <th>Total Results</th>
      <td><?php echo $ga->getTotalResults() ?></td>
    </tr>
    <tr>
      <th>Total Page views</th>
      <td><?php echo $ga->getPageviews() ?>
    </tr>
    <tr>
      <th>Total Visits</th>
      <td><?php echo $ga->getVisits() ?></td>
    </tr>
    <tr>
      <th>Total Visitors</th>
      <td><?php echo $ga->getVisitors() ?></td>
    </tr>
    <tr>
      <th>Visit Bounce Rate</th>
      <td><?php echo $ga->getVisitBounceRate() ?></td>
    </tr>
    <tr>
      <th>Results Updated</th>
      <td><?php echo $ga->getUpdated() ?></td>
    </tr>
    </table>
Path to download gapi.class.php file.

https://code.google.com/p/gapi-googl...-1.3.zip&can=2

Any idea?


-Thanks