首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >带有PHP/Curl列表消息的Gmail API

带有PHP/Curl列表消息的Gmail API
EN

Stack Overflow用户
提问于 2015-09-02 21:39:08
回答 1查看 1.9K关注 0票数 1

我正在尝试使用Google获取我的gmail消息列表。我设法获得我的联系人名单和一些其他谷歌资源使用这个卷曲方法,但我得到“无效的凭据”,每当我试图检索我的电子邮件列表。-请注意,我的范围设置正确。

下面是php代码:

代码语言:javascript
运行
复制
    <?

$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-时来自谷歌的象征性反馈

代码语言:javascript
运行
复制
{
 "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"
}

最终,如果有一种更简单和不同的方法来检索登录的用户电子邮件列表,那么这也是很棒的:)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-09-02 22:01:44

实际上密码没问题。AuthUrl生成器在我的测试服务器上设置了错误的参数。

对于那些想要使用代码的人来说,Google是示例中使用的https://github.com/google/google-api-php-client

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32363572

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档