Gmail API history request returning Drafts

谁说胖子不能爱 提交于 2019-12-12 18:07:18

问题


I posted a question abt the api returning invalid history ids. I'm trying to figure this out. I think the ids are just not valid in a messages get request, since these are not real messages, rather drafts. I don't know why history list is returning drafts for a messagesAdded request. Can somebody tell me if this is the expected behavior?

{
 "history": [
  {
   "id": "10946109",
   "messages": [
    {
     "id": "15cc8cd840c2945a",
     "threadId": "15cc5ccf65733c7f"
    }
   ],
   "messagesAdded": [
    {
     "message": {
      ...
      "labelIds": [
       "SENT"
      ]
     }
    }
   ]
  },
  {
   "id": "10975146",
   "messages": [
    {
     ...
    }
   ],
   "messagesAdded": [
    {
     "message": {
      ...
      "labelIds": [
       "DRAFT"
      ]
     }
    }
   ]
  }

If I need to filter for actual messages - not drafts, do I just do labelIds does not contain DRAFT?


回答1:


Your first question:

Can somebody tell me if this is the expected behavior?

Yes this is expected behavior (replicated). Check this Document regarding History List:

Users.history: list

Lists the history of all changes to the given mailbox. History results are returned in chronological order (increasing historyId).


Your second question:

If I need to filter for actual messages - not drafts, do I just do labelIds does not contain DRAFT?

Yes there is an actual filter. You can change the "labelId" parameter to anything except "DRAFT" so it would not return draft results in the history.

Below is a simple guide on how to properly filter your messages without returning Draft label types:

  1. To check your list of labelId's, try this Label API Test Link to see your list of labels just to be sure that you will be using a valid "labelId" later in step 3 by executing the API.

  2. Get the value of the "historyId" by executing the Message List API, retrieving a list of message then get one id then use the Message Get API by entering the ID to retrieve the "historyId". Make sure that the labelId is not a "DRAFT" type or you have to get another id from the list just to avoid returning a "DRAFT" type.

  3. Then execute History API Test Link. Enter your "userId" and the "startHistoryId"(make sure to subtract the value of the "startHistoryId" by 1) of your message and change the "labelId" by using one from the list of labels you retrieved from your GET API in step 2, change the "historyTypes" to "messagesAdded" then click execute.

It should return a list of message under the "labelId" being inputted and not a "DRAFT" type.



来源:https://stackoverflow.com/questions/44762211/gmail-api-history-request-returning-drafts

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!