Accessing Sharepoint Files with httr

This question has been asked before here but didn't receive an answer. I'll be receiving ~150 files and want to automate reading them into R. I can access them from a mapped folder but Sharepoint would be easier as it contains information about who sent the file.

When I use the following:

GET("https://mycompany-my.sharepoint.com/personal/myname/_layouts/15/doc2.aspx?sourcedoc=%7B2B1B2AA5-BA1D-41F7-A78E-3C4B9EFAF3F2%7D&file=filename.xlsx&action=default&mobileredirect=true",
    authenticate("username", "password"),
    write_disk("Data_Collection/tempfile.xlsx", overwrite = TRUE)
)

it creates the tempfile with this message in the console:

Response [https://mycompany-my.sharepoint.com/personal/myname/_layouts/15/doc2.aspx?sourcedoc=%7B2B1B2AA5-BA1D-41F7-A78E-3C4B9EFAF3F2%7D&file=filename.xlsx&action=default&mobileredirect=true]
  Date: 2020-10-01 12:50
  Status: 403
  Content-Type: text/plain; charset=utf-8
  Size: 13 B
<ON DISK>  C:\Users\Data_Collection\tempfile.xlsx

When I open the file, I get this error:

I know status 403 means the server recognized the request and refuses to authorize. How can I get around this?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.