简体   繁体   English

Gmail API。 如何获取消息标签

[英]Gmail api. How to get message labels

How to get message labelIds from Google_Service_Gmail_Message or by messageId 如何从Google_Service_Gmail_Message或通过messageId获取消息的labelIds

something like that: 像这样的东西:

$messages = $gmailService()->users_messages->listUsersMessages('me', ['q' => 'newer_than:1d in:anywhere']);

foreach ($messages as $message) {
    $messageLabels = $message->getLabelIds();
}

If you try out the API Explorer at the bottom of the page, you will see that listing messages only gives you the id of the messages: 如果您尝试使用页面底部的API资源管理器 ,则会看到列表消息仅为您提供消息的ID:

Response 响应

{
 "messages": [
  {
   "id": "1527ddcca0fd0e08",
   "threadId": "1525a22606f6d608"
  },
  {
   "id": "1527d0e3b13fab83",
   "threadId": "152792b4f30977ae"
  }, ...
 ],
 "nextPageToken": "13090329777308767238",
 "resultSizeEstimate": 100
}

You need to get these messages individually with the message id, which you can try here : 您需要使用消息ID单独获取这些消息,您可以在此处尝试

Response 响应

{
 "id": "1527ddcca0fd0e08",
 "threadId": "1525a22606f6d608",
 "labelIds": [
  "INBOX",
  "IMPORTANT",
  "CATEGORY_FORUMS"
 ],
 "historyId": "721186",
 "internalDate": "1453810567000",
 "payload": {
  "mimeType": "multipart/alternative",
  "filename": "", ...

As you can see, this response contains the labelIds . 如您所见,此响应包含labelIds

Example (just getting the first message) 示例(仅获取第一条消息)

$messages = $service->users_messages->listUsersMessages('me', ['q' => 'newer_than:1d in:anywhere']);
$list = $messages->getMessages();
$messageId = $list[0]->getId();
$message = $service->users_messages->get('me', $messageId, ['format' => 'full']);
$labelIds = $message->getLabelIds(); 

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

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