Google Api creating New Client

Thursday, July 3, 2014

I am trying to deploy the code in a server which runs Ubuntu. I had previously run the code successfully in windows using Wamp server. but when i try to run it in ubuntu, I think i am not able to create a New client. I tried changing the permission of the directories and everything.


Here's the code.



<html>
<head>
<title> Search </title>
<?php
require_once 'src/Google_Client.php';
require_once 'src/Auth/Google_OAuth2.php';
require_once 'src/contrib/Google_Oauth2Service.php';
session_start();
//unset($_SESSION['access']);
//$_SESSION['access'] = 'my_value';
$_SESSION['loginflag']=0;

$client = new Google_Client();
$client_id = 'xxx';
$client_secret = 'yyy';
$redirect_uri = 'zzz';

$client->setApplicationName("kkk");
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setRedirectUri($redirect_uri);
$client->setScopes(array('http://ift.tt/AjNHPk http://ift.tt/y4qatF'));

$oauth2 = new Google_Oauth2Service($client);

if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
$_SESSION['loginflag']=1;
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
return;
}

if (isset($_SESSION['token'])) {
$_SESSION['loginflag']=1;
$client->setAccessToken($_SESSION['token']);
}

if (isset($_REQUEST['logout'])) {
$_SESSION['loginflag']=0;
unset($_SESSION['token']);
$client->revokeToken();
}

if ($client->getAccessToken()) {
$_SESSION['loginflag']=1;
$user = $oauth2->userinfo->get();
$_SESSION['emailid'] = $email = filter_var($user['email'], FILTER_SANITIZE_EMAIL);
$personMarkup = "$email";
$_SESSION['token'] = $client->getAccessToken();
}
else{
$authUrl = $client->createAuthUrl();
$_SESSION['loginflag']=1;
header('Location: '.$authUrl);
}
?>
</head>
</html>


It still runs perfectly in Wamp server.







http://ift.tt/1mb0RcK