1

I tried Users.messages.Insert to restore the chat messages to my account. But the response was

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "invalidArgument",
    "message": "Invalid label: CHAT"
   }
  ],
  "code": 400,
  "message": "Invalid label: CHAT"
 }
}

Is there any possibility to overcome this issue.If so how? Or is there any suggestible way to restore my chat messages?

Ragavi
  • 41
  • 4
  • Can you show us the code you have written so far? – Tholle Jan 12 '16 at 11:41
  • @Tholle : Well I didn't code. I just checked it in -"https://developers.google.com/gmail/api/v1/reference/users/messages/insert#try-it " by giving the user_id and raw data – Ragavi Jan 12 '16 at 12:41
  • Oh, I see. I think you should be able to [insert](https://developers.google.com/gmail/api/v1/reference/users/messages/insert) a message, and then just [modify](https://developers.google.com/gmail/api/v1/reference/users/messages/modify) it by adding the `CHAT`-label. Have you tried that? – Tholle Jan 12 '16 at 13:03
  • @Tholle : Yea. This seems to be a good thought and I have tried it before. But then when I tried inserting a message, it didn't accept the raw data of a 'chat' message. I think it may be because the chat message may lack few parameters when compared to a normal mail (such as inbox,drafts). Alas I wasn't able to insert it as a message. Why does google restrict this feature or am I going wrong somewhere? – Ragavi Jan 12 '16 at 13:40
  • I don't know :( I have not done anything similar before. It looks like the Gmail API is not really [the correct way to go](http://stackoverflow.com/questions/24523712/access-chats-label-with-gmail-api), but I'm not sure about that either. Have you looked at the [Hangouts API](https://developers.google.com/+/hangouts/api/)? – Tholle Jan 12 '16 at 13:47
  • 1
    oh.. I don't think that Hangouts API will suffice this.. Anyway I refer to it and thanks for your response @Tholle – Ragavi Jan 12 '16 at 14:48

3 Answers3

0

If it is a regular Gmail account, then the it should be saved as any other email is. It will not end up in your inbox but if a user was chatting with "Peter" for example, you can search chat history by searching for mail from "Peter". Then emails and chat history are displayed.

You have an error, that there is no label CHAT. You need to search normally for the emails.

m.aibin
  • 3,528
  • 4
  • 28
  • 47
0

Try using Users.threads: list method. This will return the list of threads in the user's mailbox.

To specify chat messages, set userId and labelIds=CHAT

Try it here.

Response should be something like this:

{
  "threads": [
    users.threads Resource
  ],
  "nextPageToken": string,
  "resultSizeEstimate": unsigned integer
}

Hope this helps and Good luck!

Andres
  • 671
  • 4
  • 9
  • Yes. Users.threads.list method returns the threads along with message id. But I wanna insert those CHAT messages back into the user's mailbox which have been already obtained using Users.threads.list method. i.e ., I have got all the chat message using the list method(backup). Now lets say that I have accidentally deleted the chat messages in my mailbox. So I wanna insert the chat messages(which i have already backed up) into my mailbox . How do I do that? The method which you have mentioned just helps me take backup. But I wanna put it back to my mailbox. Is there any way to do so? – Ragavi Jan 13 '16 at 05:59
0

The Gmail API doesn't provide a means to restore a chat message AS a chat message. The best you can do is create a regular email message (via Gmail.message.insert) and fill it with the chat message's content.

Ryan Roth
  • 1,394
  • 9
  • 15