Afficher quelque resultats de Google Analytique sur son site

WRInaute discret
Bonjour,
J'essaie d'installer cette api, mais j'ai cette erreur
Code:
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/www/8e78bff14408a9a3cac59710019b37f0/web/GAnalytics.class.php on line 14

Visible ici : http://www.freeetv.com/script/an.php

à la ligne 14 de GAnalytics.class.php il y a ça :
Code:
private $_username, $_password, $_cookie, $_ch;

Une idée d'où cela bug ?

Merci !
 
WRInaute passionné
Greg_FreeeTV a dit:
Bonjour,
J'essaie d'installer cette api, mais j'ai cette erreur
Code:
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/www/8e78bff14408a9a3cac59710019b37f0/web/GAnalytics.class.php on line 14

Visible ici : http://www.freeetv.com/script/an.php

à la ligne 14 de GAnalytics.class.php il y a ça :
Code:
private $_username, $_password, $_cookie, $_ch;

Une idée d'où cela bug ?

Merci !
il me semble que si tu as un vieux php il faut enlever le "private"
 
WRInaute discret
J'ai la VERSION DE PHP: 4.4.4, c'est effectivement pas la 5.

Mais si j'enlève la ligne privat après j'ai le même problème avec les lignes suivantes...

Code:
class GAnalytics
{
  private $_username, $_password, $_cookie, $_ch;
  public $id, $ldate, $bdate, $lang;
  
  public function __construct($email, $password)
  {
    $this->_username = urlencode($email);
    $this->_password = $password;
    $this->_cookie = "./.gacookie";
    $this->_ch = curl_init();
    $this->ldate = 0;
    $this->bdate = 0;
  }
  
  public function connect($id, $lang = 'en_US')
  { // Connection to our google account
    $this->id = $id; // file id.......................etc....etc.....

Donc si je reste en php4 c'est cuit ! ??
 
WRInaute passionné
J'ai la VERSION DE PHP: 4.4.4

J'espère que bien qu'une version 5 soit sortie, on ne va pas concidérer la 444 comme vielle.
il y a tout de même pas mal de changement pour basculer vers la 5. tout le monde n'est pas encore prêt à migrer.
 
WRInaute passionné
ce qui doit marcher avec PHP 4.4.4 :
Code:
class GAnalytics
{
  var $_username, $_password, $_cookie, $_ch;
  var $id, $ldate, $bdate, $lang;
 
  function __construct($email, $password)
  {
    $this->_username = urlencode($email);
    $this->_password = $password;
    $this->_cookie = "./.gacookie";
    $this->_ch = curl_init();
    $this->ldate = 0;
    $this->bdate = 0;
  }
 
  function connect($id, $lang = 'en_US')
  { // Connection to our google account
    $this->id = $id; // file id.......................etc....etc.....
 
WRInaute discret
Merci webmasterlamogere.

J'ai effectué tes changements, et m'en suit inspiré pour la suite du code en virant des public et privat.

Il y a encore un problème avec "new"

Parse error: syntax error, unexpected T_NEW in /home/www/8e78bff14408a9a3cac59710019b37f0/web/GAnalytics.class.php on line 53
if (!$query) { throw new Exception("The view is not specified !"); }
Je met tout le code cette fois...

Code:
<?php
/**
 * Google Analytics (hacked) API Class
 * @author     Sebastien Dudek (FlUxIuS)
 * @website    Slashon.com
 * @email      sebastien.dudek@slashon.com 
 * @tools      cUrl+PHP
 * @version    0.1
 * @Licence    Free&Contribute 
 */

class GAnalytics 
{ 
  var $_username, $_password, $_cookie, $_ch; 
  var $id, $ldate, $bdate, $lang; 
  
  function __construct($email, $password) 
  { 
    $this->_username = urlencode($email); 
    $this->_password = $password; 
    $this->_cookie = "./.gacookie"; 
    $this->_ch = curl_init(); 
    $this->ldate = 0; 
    $this->bdate = 0; 
  } 
  
  function connect($id, $lang = 'en_US') 
  { // Connection to our google account 
    $this->id = $id; // file id
    $postdata="Email=$this->_username&Passwd=$this->_password&GA3T=5AS_gBsvDHI&nui=15&fpui=3&askapache=http://www.askapache.com/"
."&service=analytics&ifr=true&rm=hide&itmpl=true&hl={$lang}&alwf=true&continue=https://www.google.com/analytics/settings/";
    curl_setopt($this->_ch, CURLOPT_URL,"https://www.google.com/accounts/ServiceLoginBoxAuth");
    curl_setopt($this->_ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($this->_ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
    curl_setopt($this->_ch, CURLOPT_TIMEOUT, 60);
    curl_setopt($this->_ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($this->_ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($this->_ch, CURLOPT_COOKIEJAR, $this->_cookie);
    curl_setopt($this->_ch, CURLOPT_COOKIEFILE, $this->_cookie);
    curl_setopt($this->_ch, CURLOPT_REFERER, 'https://www.google.com/analytics/');
    curl_setopt($this->_ch, CURLOPT_POSTFIELDS, $postdata);
    curl_setopt($this->_ch, CURLOPT_POST, 1);
    
    curl_exec($this->_ch);
  }
  
  function query($query, $type)
  { /* 
      Redirection to our report by a type and a category 
      4 type : PDF(0), XML(1), CVS(2), TSV(3)
      4 Categories : DashboardReport, VisitorsOverviewReport, TrafficSourcesReport, ContentReport
    */
  if (!$query) { throw new Exception("The view is not specified !"); }
    $this->chdate(); // Check the date
    curl_setopt($this->_ch, CURLOPT_URL,"https://www.google.com/analytics/reporting/export?fmt={$type}&id={$this->id}&pdr={$this->bdate}-{$this->ldate}&cmp=average&&rpt={$query}");
    $result = curl_exec($this->_ch);
    if (($type === 0) && eregi('DashboardReport|VisitorsOverviewReport|TrafficSourcesReport|ContentReport', $query))
    {
      header('Content-type: application/pdf', true);
      echo $result;
    } elseif (($type === 1) && eregi('DashboardReport|VisitorsOverviewReport|TrafficSourcesReport|ContentReport', $query)) {
      header('Content-type: application/xml; charset="utf-8"',true);
      echo $result;
    } elseif (($type === 2) && eregi('TrafficSourcesReport|ContentReport', $query)) {
      header('Content-type: application/vnd.ms-excel; charset="utf-8"', true); 
      echo $result;
    } elseif (($type === 3) && eregi('TrafficSourcesReport|ContentReport', $query)) {
      header('Content-type: application/tsv; charset="utf-8"', true); 
      echo $result;
    } else {
      throw new Exception("Category or Type Error !");
    }
  }
  
  function chdate()
  { /* Check date : Returns two default dates if the propositions are wrong */
    $t_bdate = str_split($this->bdate, 2);
    $t_ldate = str_split($this->ldate, 2);
    
    if ((!checkdate($t_bdate[3],$t_bdate[2],$t_bdate[0].$t_bdate[1])) || (!checkdate($t_ldate[3],$t_ldate[2],$t_ldate[0].$t_ldate[1])))
    { 
      $this->ldate = date("Ymd", mktime(0, 0, 0, date('m'), date('d')-1, date('Y')));
      $this->bdate = date("Ymd", mktime(0, 0, 0, date('m')-1, date('d'), date('Y')));
    } else {
      $this->bdate = $this->bdate;
      $this->ldate = $this->ldate;
    }
  }
  
  function close()
  { /* Close all */
    curl_close($this->_ch);
    @unlink($this->_cookie);
    exit;
  }
}
?>
 
WRInaute discret
OK le Die à la ligne 53 et 71 donne un nouveau type d'erreur

Code:
Warning: curl_setopt(): supplied argument is not a valid cURL handle resource in /home/www/8e78bff14408a9a3cac59710019b37f0/web/GAnalytics.class.php on line 32

Warning: curl_setopt(): supplied argument is not a valid cURL handle resource in /home/www/8e78bff14408a9a3cac59710019b37f0/web/GAnalytics.class.php on line 33

Warning: curl_setopt(): supplied argument is not a valid cURL handle resource in /home/www/8e78bff14408a9a3cac59710019b37f0/web/GAnalytics.class.php on line 34

Warning: curl_setopt(): supplied argument is not a valid cURL handle resource in /home/www/8e78bff14408a9a3cac59710019b37f0/web/GAnalytics.class.php on line 35

Warning: curl_setopt(): supplied argument is not a valid cURL handle resource in /home/www/8e78bff14408a9a3cac59710019b37f0/web/GAnalytics.class.php on line 36

Warning: curl_setopt(): supplied argument is not a valid cURL handle resource in /home/www/8e78bff14408a9a3cac59710019b37f0/web/GAnalytics.class.php on line 37

Warning: curl_setopt(): supplied argument is not a valid cURL handle resource in /home/www/8e78bff14408a9a3cac59710019b37f0/web/GAnalytics.class.php on line 38

Warning: curl_setopt(): supplied argument is not a valid cURL handle resource in /home/www/8e78bff14408a9a3cac59710019b37f0/web/GAnalytics.class.php on line 39

Warning: curl_setopt(): supplied argument is not a valid cURL handle resource in /home/www/8e78bff14408a9a3cac59710019b37f0/web/GAnalytics.class.php on line 40

Warning: curl_setopt(): supplied argument is not a valid cURL handle resource in /home/www/8e78bff14408a9a3cac59710019b37f0/web/GAnalytics.class.php on line 41

Warning: curl_setopt(): supplied argument is not a valid cURL handle resource in /home/www/8e78bff14408a9a3cac59710019b37f0/web/GAnalytics.class.php on line 42

Warning: curl_exec(): supplied argument is not a valid cURL handle resource in /home/www/8e78bff14408a9a3cac59710019b37f0/web/GAnalytics.class.php on line 44

Fatal error: Call to undefined function: str_split() in /home/www/8e78bff14408a9a3cac59710019b37f0/web/GAnalytics.class.php on line 76

J'avais essayé auparavant de supprimer ces deux lignes et les erreurs étaient les mêmes.
 
Discussions similaires
Haut