3

The syntax of save_attachments() function is

save_attachments(x, attachment_id = NULL, path = "", user_id = "me")

Arguments

x : message with attachment

How do I get the Message with attachment(message object) ?? I just gave the messageid taken from message header and passed it to x and I am getting the below error : x$payload : $ operator is invalid for atomic vectors

attachment_id : id of the attachment to save, if none specified saves all attachments

path : where to save the attachments

user_id : gmail user_id to access, special value of 'me' indicates the authenticated user.

Can some one help me with what value should be passed to "x"? there is no information on this gmailr package document

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197
gowtham Y.R
  • 111
  • 1
  • 2
  • 10
  • What exactly did you pass to the function? A [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) showing the problematic code would be helpful. – MrFlick Nov 28 '15 at 02:54
  • Below is the code : save_attachments(x,attachment_id=NULL,path="C:\Users\gowtham\Downloads\Textmining",user_id="me") where x=> is the messageid that i obtained from message header – gowtham Y.R Nov 28 '15 at 03:03
  • 1
    You've left off the important bit which is how you are creating `x`. Plus you should edit your question to include important info like this rather than put it in comments. You should be passing in a message object, not a message id. – MrFlick Nov 28 '15 at 03:15
  • hi MrFlick thanks for your reply , I have updated the question now .. Can you please help me understand on how to define the message object , Any sample or on info on how to get the message id would be great – gowtham Y.R Nov 28 '15 at 03:27
  • How about `save_attachments(message("messageid"),path="C:\Users\gowtham\Downloads\Textminin‌​g",user_id="me")` – MrFlick Nov 28 '15 at 05:23
  • Yes that solved the issue thanks :) – gowtham Y.R Nov 28 '15 at 06:10
  • Hi Roman , Yes that obvious we have to give double "\\" when giving path – gowtham Y.R Nov 30 '15 at 03:18
  • Having a similar issue found here: https://stackoverflow.com/questions/54298352/read-all-excel-attachments-from-gmail-folder – nak5120 Jan 21 '19 at 22:14

1 Answers1

4

save_attachments() needs message id's.

You can get a full list of messages by:

mssgs = messages(search="somedetail",num_results = NULL, label_ids = NULL,include_spam_trash = NULL,page_token = NULL, user_id = "me")

Next you can save attachments of all these messages by using a loop over the message id's:

for (i in 1:100){
    ids = id(mssgs)
    Mn = message(ids[i], user_id = "me")
    path = "/yourpath"
    save_attachments( Mn, attachment_id = NULL, path, user_id = "me")
}

Hope this helps someone in the future, took me a while to figure out while it is pretty simple.

MDEWITT
  • 2,338
  • 2
  • 12
  • 23
Piet93
  • 169
  • 1
  • 13
  • I have a similar question which I am having issues with too if you have dealt with this in the past: https://stackoverflow.com/questions/54298352/read-all-excel-attachments-from-gmail-folder – nak5120 Jan 21 '19 at 22:14