[英]Fetch emails from Gmail via OAuth2
I'm trying to fetch emails from gmail using PHP and CodeIgniter, and an OAuth2 library. 我正在尝试使用PHP和CodeIgniter和OAuth2库从gmail提取电子邮件。 I have already got OAuth2 set up to get the users access token, etc. I can get the users info by doing 我已经设置了OAuth2来获取用户访问令牌等。我可以通过执行以下操作获取用户信息
public function get_user_info(OAuth2_Token_Access $token)
{
$url = 'https://www.googleapis.com/oauth2/v1/userinfo?alt=json&'.http_build_query(array(
'access_token' => $token->access_token,
));
$user = json_decode(file_get_contents($url), true);
return array(
'uid' => $user['id'],
'nickname' => url_title($user['name'], '_', true),
'name' => $user['name'],
'first_name' => $user['given_name'],
'last_name' => $user['family_name'],
'email' => $user['email'],
'location' => null,
'image' => (isset($user['picture'])) ? $user['picture'] : null,
'description' => null,
'urls' => array(),
);
}
What I want to do now is fetch some emails. 我现在想做的是获取一些电子邮件。 I've googled for some code on how to get emails but the only thing I can see is https://mail.google.com/mail/feed/atom/
. 我已经在Google上搜索了一些有关如何获取电子邮件的代码,但是我唯一能看到的是https://mail.google.com/mail/feed/atom/
。 I found this on the Google OAuth2 Playground but I can't figure out how to use it apart from navigating to it directly. 我在Google OAuth2 Playground上找到了它,但是除了直接导航到它之外,我不知道该如何使用它。
Can anyone give me some suggestions? 谁能给我一些建议? Ideally I want to fetch emails that are not just new (this seems to be what the link above does). 理想情况下,我想获取不只是新的电子邮件(这似乎就是上面链接的作用)。
Using a REST-based interface you can currently only get the unread messages feed . 使用基于REST的界面,您当前只能获取未读消息feed 。 If you want to access all emails of a user, you have to use IMAP. 如果要访问用户的所有电子邮件,则必须使用IMAP。 Google developed a method to do IMAP/SMTP authentication using OAuth2 that you can use. Google开发了一种使用OAuth2进行IMAP / SMTP身份验证的方法 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.