簡體   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.

請注意,我不想將 email 發送給收件人,但想在我的網站上獲取我的整個收件箱電子郵件列表。 有沒有人遇到這個問題並得到任何結果?

如果您想檢索您的 email 收件箱然后在您的網站中使用這些消息,您可以結合方法users.messages.list()它將返回您的 email 消息 ID 的列表,如文檔中所述以及users.messages.get ()這將返回消息本身。

在 PHP 中,這些方法將是listUserMessages並返回一個ListMessagesResponse和一個GmailMessage 使用它們,您可以將每條消息的內容存儲為數組的元素,然后以您喜歡的方式在您的網站中使用該數組。

以下代碼假定您已正確授權您的應用程序,並且只關注在 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