我正在尝试使用Google获取我的gmail消息列表。我设法获得我的联系人名单和一些其他谷歌资源使用这个卷曲方法,但我得到“无效的凭据”,每当我试图检索我的电子邮件列表。-请注意,我的范围设置正确。
下面是php代码:
<?
$thetokenarray=array();
$thetokenarray= json_decode($_SESSION["token"] ,true);
$thetoken = $thetokenarray["access_token"] ;
$thedomain = substr(strrchr($_SESSION["email"], "@"), 1);
$ch = curl_init();
$headers = array("Authorization: access_token ".$thetoken."");
print_r($headers);
curl_setopt($ch, CURLOPT_URL, 'https://www.googleapis.com/gmail/v1/users/enattee%40gmail.com/messages');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
curl_close($ch);
$response = json_decode($response,true);
print_r($response);
?>
这是谷歌的答案:
数组( error => Array (error => Array (域=>全局原因=> authError message => locationType =>报头位置=>授权)编码=> 401 message =>无效凭据))
下面是我在使用Qy3oGrcF-时来自谷歌的象征性反馈
{
"issued_to": "64125009955-1hlmj0jgi9j2hd4sxxxxxaem9c9qhqcf8f.apps.googleusercontent.com",
"audience": "64125xxxx09955-1hlmj0jgixxxxx9c9qhqcf8f.apps.googleusercontent.com",
"user_id": "10597422xxxx25084",
"scope": "https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/gmail.readonly https://www.google.com/m8/feeds/ https://www.googleapis.com/auth/admin.directory.user.readonly https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/plus.profile.emails.read https://www.googleapis.com/auth/plus.moments.write https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/plus.profile.agerange.read https://www.googleapis.com/auth/plus.profile.language.read https://www.googleapis.com/auth/plus.circles.members.read",
"expires_in": 3427,
"email": "exxx@gmail.com",
"verified_email": true,
"access_type": "offline"
}
最终,如果有一种更简单和不同的方法来检索登录的用户电子邮件列表,那么这也是很棒的:)
发布于 2015-09-02 22:01:44
实际上密码没问题。AuthUrl生成器在我的测试服务器上设置了错误的参数。
对于那些想要使用代码的人来说,Google是示例中使用的https://github.com/google/google-api-php-client。
https://stackoverflow.com/questions/32363572
复制相似问题