1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
<?php
$email="votremail";
$pass="votrepass";
//requête HTTP fonctionnel réponse HTTP 200
function googleHTTP($email,$pass){
$url="https://www.google.com/accounts/ClientLogin";
$ch=curl_init();
$dataPOST=array(
"accountType"=>"HOSTED_OR_GOOGLE",
"Email"=>$email,
"Passwd"=>$pass,
"service"=>"cl",
"source"=>"develop-test-6.789");
//option des en-tête HTTP
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_0);
curl_setopt($ch,CURLOPT_CRLF,false);
curl_setopt ($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HEADER,true);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataPOST);
//reponse requête HTTP
$ret=curl_exec($ch);
//var_dump($ret);
//curl_getinfo donne des information concernant l'exécution de la requête
// var_dump(curl_getinfo($ch));
curl_close($ch);
return $ret;
}
//requête d'authentification HTTP sur le compte google
function googleAuth($token){
$url="https://www.google.com/accounts/ClientLogin";
$header[]="Authorization: GoogleLogin auth=". $token;
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_MUTE, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);//
$ret=curl_exec($ch);
curl_close($ch);
// var_dump($ret);
return $ret;
}
//retourne un tableau avec les ids HTTP
function getIDtab($email,$pass){
$tmpid=explode("\n",googleHTTP($email,$pass));
$fin=count($tmpid)-1;
for($i=0;$i<$fin;$i++){
$t=explode("=",$tmpid[$i]);
$tmp[((string)$t[0])]=$t[1];
}
return $tmp;
}
//retourne l'identifiant souhaité Auth,SID,LSID
function getIDuser($tbl,$string){
foreach($tbl as $k=>$v){
if($k==$string)
return $v;
}
}
//récupérer l'identifiant souhaité
$token=getIDuser(getIDtab($email,$pass),"Auth");
echo googleAUTH(getIDuser($token, "Auth"));
?> |
Partager