Hello all,
I need to validate google oauth2 access token... I found one script online but it is stuck on cURL function... I suppose JSON to ARRAY conversion or something similar.. but I dont know how to solve it.... can anyone show me? PLEASE!!!
when I run it... it gives me this error:
Notice: Trying to get property of non-object in C:\xampp\htdocs----
**
Here is the script:**
<?php
define('CLIENTID','xxxxxxxxxxxx.apps.googleusercontent.com');
define('CLIENTSECRET','xxxxxxxxxxxxxxxxxxxxxxx');
define('URLCALLBACK', 'http://xxxxx.com/googcallback.php');
define('URL','http://xxxxx.com/');
function request_token($code){
//Solicita el token a google a con el código pasado
$tokendata = array();
$ch = curl_init('https://accounts.google.com/o/oauth2/token');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "code=".$code."&client_id=".CLIENTID."&client_secret=".CLIENTSECRET."&redirect_uri=".URLCALLBACK."&grant_type=authorization_code");
curl_setopt($ch, CURLOPT_RETURNTRANSFER , 1);
$result_curl = curl_exec($ch);
$error_curl = curl_error($ch);
curl_close($ch);
* $res = json_decode($result_curl);
if ($res->access_token){
$tokendata['token_access']=$res->access_token;
}
if ($res->token_type){
$tokendata['token_type']=$res->token_type;
}
if ($res->expires_in){
$tokendata['token_expires_in']=$res->expires_in;
}
if ($res->id_token){
$tokendata['token_id']=$res->id_token;
}
return $tokendata;
}*
$code='';
$param='';
$tokendata = array();
if(isset($_GET['code']) && $_GET['code']){
$code = $_GET['code'];
}
if ($code){
$tokendata = request_token($code);
}
?>