function code2token($code) {
$oauth2token_url = "https://accounts.google.com/o/oauth2/token";
$clienttoken_post = array(
"code" => $code,
"client_id" => '524478858957-keh6dvesm9ml3kdv67qtk8vlqori8l3r.apps.googleusercontent.com',
"client_secret" => 'cws9DqO',
"redirect_uri" => 'http://cc.cr/redir.php',
"grant_type" => "authorization_code"
);
$curl = curl_init($oauth2token_url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $clienttoken_post);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$json_response = curl_exec($curl);
curl_close($curl);
$authObj = json_decode($json_response);
if (isset($authObj->refresh_token)){
global $refreshToken;
$refreshToken = $authObj->refresh_token;
}
$accessToken = $authObj->access_token;
return $accessToken;
}
function call_api($accessToken,$url){
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$curlheader[0] = "Authorization: Bearer " . $accessToken;
curl_setopt($curl, CURLOPT_HTTPHEADER, $curlheader);
$json_response = curl_exec($curl);
curl_close($curl);
$responseObj = json_decode($json_response);
return $responseObj;
}
if(isset($_REQUEST['code'])){
$data = call_api(code2token($_REQUEST['code']),"https://www.googleapis.com/oauth2/v1/userinfo");
echo print_r($data);//array of user profile details name,email,etc
}
30 September 2012
4 July 2012
unknown file size while downloading via php script
if your browser doesn't appear to be obeying the headers generated by your PHP script—especially Content-Length—it is fairly likely that Apache's mod_deflate extension is enabled.
You can easily disable it for a single script using the following line in an applicable .htaccess file:
SetEnvIfNoCase Request_URI ^/download\.php no-gzip dont-vary
thanks to http://paul.luminos.nl/show_post.php?p=471
7 June 2012
reset mysql root password
ps -ef | grep mysql - checks if mysql/mysqld is one of the running processes.
pkill mysqld - kills the daemon, if it is running.
mysqld_safe --skip-grant-tables & - Run MySQL safe daemon with skipping grant tables
mysql -u root mysql - Login to MySQL as root with no password
UPDATE user SET password=PASSWORD("your-new-passowrd") WHERE user="root";
FLUSH PRIVILEGES;
Done
12 May 2012
services and its port
netstat -antp | grep LISTEN
25 March 2012
unique combination of multiple columns in mysql
alter table tablename add unique index(column1,column2,column3);
14 March 2012
[mysql ] perform order by column and rand() in single query
)SELECT * FROM ( SELECT * FROM table1 ORDER BY nos desc limit 0,1)
T1 ORDER BY RAND()
usage:
if the column nos is same in multipe rows then fetch a random row..
29 February 2012
How to install the Sun Java JDK on Ubuntu 10.10?
sudo apt-get install python-software-properties sudo add-apt-repository ppa:sun-java-community-team/sun-java6 sudo apt-get update sudo apt-get install sun-java6-jdk
Subscribe to:
Posts (Atom)