简体   繁体   English

Using Gmail Api with Laravel PHP to read all gmail inbox on website and then respond to a particular email

[英]Using Gmail Api with Laravel PHP to read all gmail inbox on website and then respond to a particular email

I want to access my gmail inbox list in laravel php using Gmail API.I can do it on the console using PHP but it is difficult to find the sources to run the code on website using Laravel Framework. I want to access my gmail inbox list in laravel php using Gmail API.I can do it on the console using PHP but it is difficult to find the sources to run the code on website using Laravel Framework.

Note that I don't want to send the email to the recipient but wanted to fetch my whole inbox list of emails on my website.请注意,我不想将 email 发送给收件人,但想在我的网站上获取我的整个收件箱电子邮件列表。 Had anyone face this issue and got any result?有没有人遇到这个问题并得到任何结果?

If you want to retrieve your email inbox to then use these messages in your website you can combine the method users.messages.list() which will return a list of your email messages ids as described in the documentation along with users.messages.get() which will return the message itself.如果您想检索您的 email 收件箱然后在您的网站中使用这些消息,您可以结合方法users.messages.list()它将返回您的 email 消息 ID 的列表,如文档中所述以及users.messages.get ()这将返回消息本身。

In PHP these methods would be listUserMessages and get returning each a ListMessagesResponse and a GmailMessage .在 PHP 中,这些方法将是listUserMessages并返回一个ListMessagesResponse和一个GmailMessage With them you can store the content of each message as an element of an array to then use this array in your website in your preferred way.使用它们,您可以将每条消息的内容存储为数组的元素,然后以您喜欢的方式在您的网站中使用该数组。

The following piece of code assumes that you have authorised your application correctly and only focuses on the logic to get an array of your inbox in PHP, it also has self explanatory comments:以下代码假定您已正确授权您的应用程序,并且只关注在 PHP 中获取收件箱数组的逻辑,它也有自我解释的注释:

 // Run the method list which will return the list of messages $list = $gmail->users_messages->listUsersMessages('me'); // Get the actual list $messageList = $list->getMessages(); // Create array where we will store our messages $messages = array(); // iterate over all the elements retrieved by the method list foreach($messageList as $msg){ // GET individual message $message = $gmail->users_messages->get('me',$msg->id); // Push the element into our array of messages array_push($messages,) }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM