1
votes

Is there any way to get send date of hangout message?

Goal: Fetch all messages from google (emails, and hangouts) and date in which there where sent.

As is: I'm using Gmail-API, messages.get() endpoint. When Im fetching this endpoint with query: in:!chats aka email messages, all works great. But if I invoke this with query: in:chats (hangouts messages), the endpoint will return less information than normal message, and unfortunately it won't have send at date.

Is there any way to get send at date from hangout message?

1
You cannot get start date of message with Gmail API. You can get the message id(of chats) with message.list, but message.get dosent give any of info about the start date. But in message.list, in query, you can pull messages by giving the start date and end date. check this link support.google.com/mail/answer/7190?hl=en - SGC
Ok, it's a good idea with message.list query, but in my app I think it may be inefficient in my case (I need to group messages in one-days-coups - so I'd need to send request for every day - can improve it by divide and conquer, but still). - matDobek
and about: You cannot get start date of message with Gmail API, for emails I can: screencast.com/t/ncjnbHaKVt - matDobek

1 Answers

0
votes

I would advice you to list entire chat conversations with threads.list() instead.

query = in:chat

GET https://www.googleapis.com/gmail/v1/users/me/threads?q=in%3Achat&access_token={YOUR_API_KEY}

Response:

{
 "threads": [
  {
   "id": "14786647099d3243",
   "snippet": "until I 😃...",
   "historyId": "147978"
  }, ...
 ]
}

Then, just issue a thread.get()-request on each chat conversation, explicitly asking for the internalDate-parameter, and you will have when every message was sent in the chat.

fields = messages(id,internalDate)

GET https://www.googleapis.com/gmail/v1/users/me/threads/14786647099d3243?fields=messages(id%2CinternalDate)&key={YOUR_API_KEY}

Response:

{
 "messages": [
  {
   "id": "14786647099d3243",       // The Id of the chat message.
   "internalDate": "1406709035161" // Time in ms when the message was created.
  },
  {
   "id": "14786650de543fa8",
   "internalDate": "1406709075429"
  }, ...
 ]
}