我使用 cURL 获得了一个 php 代码来获取 Gmail 帐户的 Google 身份验证令牌。我将它用于C2DM
. 每次我运行该脚本时,我都会收到一个不同的身份验证令牌。我认为每个谷歌帐户都有一个身份验证令牌,有时只会刷新。但正如我所说,我每次都得到不同的令牌。我应该如何管理如此频繁更改的令牌?使用令牌的更好方法是什么?
这是我用于为我的 gmail 帐户获取 AUTH TOKEN 的代码。
<?php
$ch_cl = curl_init();
curl_setopt($ch_cl, CURLOPT_URL, "https://www.google.com/accounts/ClientLogin");
curl_setopt($ch_cl, CURLOPT_FOLLOWLOCATION, true);
$data_cl = array('accountType' => 'GOOGLE',
'Email' => 'xxxxxx@gmail.com',
'Passwd' => 'xxxxxxxx',
'source'=>'xxx-xxx-0.1',
'service'=>'ac2dm'
);
curl_setopt($ch_cl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch_cl, CURLOPT_POST, true);
curl_setopt($ch_cl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch_cl, CURLOPT_POSTFIELDS, $data_cl);
$cLresponse = curl_exec($ch_cl);
// echo $cLresponse;
curl_close($ch_cl);
//parse the $cLresponse and pick out the clientLogin 'Auth' token
$cLrespArrys = explode("\n", $cLresponse);
$authStr = explode("=", $cLrespArrys[2]);
// echo "return is:<br>" . $authStr[0] . "=" . $authStr[1];
$auth = $authStr[1];
echo "<br><br>" . $auth;
?>
这里 $auth 包含颁发的 AUTH TOKEN。