FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Authentication code creation for google analytics API in PHP
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Authentication code creation for google analytics API in PHP [message #169736] Fri, 24 September 2010 11:34 Go to next message
neha rathi is currently offline  neha rathi
Messages: 4
Registered: September 2010
Karma: 0
Junior Member
Hi,

Can sombody tell me how to create Authentication code for google
analytics API.
There are so many big big documentation on google but still I am not
getting it?

Do it requires SSL Certification as well.

Please help.

Neha.
Re: Authentication code creation for google analytics API in PHP [message #169737 is a reply to message #169736] Fri, 24 September 2010 12:09 Go to previous messageGo to next message
Erwin Moller is currently offline  Erwin Moller
Messages: 228
Registered: September 2010
Karma: 0
Senior Member
On 9/24/2010 1:34 PM, neha rathi wrote:
> Hi,
>
> Can sombody tell me how to create Authentication code for google
> analytics API.
> There are so many big big documentation on google but still I am not
> getting it?
>
> Do it requires SSL Certification as well.
>
> Please help.
>
> Neha.

Are you looking for something like this?
http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=6698 3

And you'll have to read through it to get the idea.

Regards,
Erwin Moller


--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
Re: Authentication code creation for google analytics API in PHP [message #169762 is a reply to message #169737] Sat, 25 September 2010 04:48 Go to previous messageGo to next message
neha rathi is currently offline  neha rathi
Messages: 4
Registered: September 2010
Karma: 0
Junior Member
Hi,

I am not getting any problem in installing Analytics code in websites.
I am trying a code in which I am collecting daily visits of all
domains of my google analytics account on one page.
It requires a google analytics API. In which it requires google
authentication code. my doubt is how to get it.
Without that code I am getting all visits on local xampp server but
not on dedicated server.

It gives me error as


Fatal error: Uncaught exception 'Exception' with message 'Permission
Denied - <HTML> <HEAD> <TITLE>Token invalid</TITLE> </HEAD> <BODY
BGCOLOR="#FFFFFF" TEXT="#000000"> <H1>Token invalid</H1> <H2>Error
401</H2> </BODY> </HTML> ' in /home/gauravhm/public_html/seo/admin/
domain_add/googleanalytics.class.php:266 Stack trace: #0 /home/
gauravhm/public_html/seo/admin/domain_add/
googleanalytics.class.php(195): GoogleAnalytics->_postTo('https://
www.goo...', Array, Array) #1 /home/gauravhm/public_html/seo/admin/
domain_add/googleanalytics.class.php(116): GoogleAnalytics-
> _callAPI('https://www.goo...') #2 /home/gauravhm/public_html/seo/
admin/domain_add/visits.php(76): GoogleAnalytics->getReport(Array) #3
{main} thrown in /home/gauravhm/public_html/seo/admin/domain_add/
googleanalytics.class.php on line 266


I am using the code snippet as


private function _callAPI($url)
{
return $this->_postTo($url,array(),array("Authorization:
GoogleLogin auth=".$this->_authCode));
}

/**
* Authenticate the email and password with Google, and set the
$_authCode return by Google
*
* @param none
* @return none
*/
private function _authenticate() {
$postdata = array(
'accountType' => 'GOOGLE',
'Email' => $this->_email,
'Passwd' => $this->_passwd,
'service' => 'analytics',
'source' => 'askaboutphp-v01'
);

$response = $this->_postTo("https://www.google.com/accounts/
ClientLogin", $postdata);
//process the response;
if ($response) {
preg_match('/Auth=(.*)/', $response, $matches);
if(isset($matches[1])) {
$this->_authCode = $matches[1];
return TRUE;
}
}
return FALSE;
}

/**
* Performs the curl calls to the $url specified.
*
* @param string $url
* @param array $data - specify the data to be 'POST'ed to $url
* @param array $header - specify any header information
* @return $response from submission to $url
*/
private function _postTo($url, $data=array(), $header=array()) {

//check that the url is provided
if (!isset($url)) {
return FALSE;
}

//send the data by curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
if (count($data)>0) {
//POST METHOD
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
} else {
$header[] = array("application/x-www-form-urlencoded");
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
}

$response = curl_exec($ch);
$info = curl_getinfo($ch);

curl_close($ch);

//print_r($info);
//print $response;
if($info['http_code'] == 200) {
return $response;
} elseif ($info['http_code'] == 400) {
throw new Exception('Bad request - '.$response);
} elseif ($info['http_code'] == 401) {
throw new Exception('Permission Denied - '.$response);
} else {
return FALSE;
}

}


Please help.
Re: Authentication code creation for google analytics API in PHP [message #169763 is a reply to message #169762] Sat, 25 September 2010 09:16 Go to previous message
Captain Paralytic is currently offline  Captain Paralytic
Messages: 204
Registered: September 2010
Karma: 0
Senior Member
On Sep 25, 5:48 am, neha rathi <rth.n...@gmail.com> wrote:
> Please help.

Certainly I'll help.

This is a problem with using the GA API. Ask in the GA API forum.

A link to it can be found here:
http://analytics.blogspot.com/2009/04/attention-developers-google-analytics ..html
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Are there C libraries that are comparable to the PHP libraries?
Next Topic: Capture logoff on browser close
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 10 14:49:37 GMT 2024

Total time taken to generate the page: 0.02830 seconds