Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download attachment from gmail using R?

Tags:

r

gmail

gmail-api

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

like image 211
gowtham Y.R Avatar asked Oct 23 '25 10:10

gowtham Y.R


1 Answers

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.

like image 130
Piet93 Avatar answered Oct 26 '25 01:10

Piet93



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!