2

I've tried all the different ways I could find on Stack Overflow but they all throw 403 Forbidden error. Some of the codes I've tried:

library(RCurl)
webpage <- getURL("https://companyname.sharepoint.com/folder1/folder2/Shared%20Documents/filename.txt", userpwd = "username@companyname.com:mypassword")
tc <- textConnection(webpage)
readLines(tc)
require(httr)
url <- "https://companyname.sharepoint.com/folder1/folder2/Shared%20Documents/filename.csv"
r <- GET(url, authenticate("username@companyname.com","mypassword", type="any"))
library(readxl)
r <- read_excel('https://companyname.sharepoint.com/folder1/folder2/Shared%20Documents/filename.xlsx
', 'Sheet1', skip=1)

They all threw 403. Only exception was when I tried the 2nd example but with type="ntlm" which threw a 401 error. I'm really at a loss. What am I doing wrong? I've triple checked to make sure my user name and passwords are correct... I know I can sync my local folder to Sharepoint and read from there but my current workflow requires me to read directly from Sharepoint.

DJL
  • 144
  • 1
  • 12
  • I am not knowledgeable about the SharePoint API but it would be my guess that you have to be authenticated before such requests to the API can be done successfully. – Paul van Oppen May 14 '20 at 00:41
  • @PaulvanOppen, I thought I was authenticating by providing my user name and password, is that not sufficient? – DJL May 14 '20 at 01:42
  • Not sure; you should consult the SharePOint API guidelines. – Paul van Oppen May 14 '20 at 01:54

2 Answers2

0

Are you on Windows? If yes, open that SharePoint site in explorer view and then map it to a drive eg. K: drive and then use the path K:/my SharePoint folder/myfile.txt to read the file.

Vishal Katti
  • 532
  • 2
  • 6
  • Isn't this basically what I said in the last sentence? "I know I can sync my local folder to Sharepoint and read from there but my current workflow requires me to read directly from Sharepoint." – DJL May 15 '20 at 01:53
0

This worked for me. Note the @SSL added after companyname.com

TEST <- readr::read_lines("//mysite.companyname.com@SSL/personal/my_username/Documents/Shared with Everyone/My_Test_File.txt")
TEST
Vishal Katti
  • 532
  • 2
  • 6
  • Did you mean after ```sharepoint.com```? My path shows in the form of ```companyname.sharepoint.com```... in any case, I tried appending ```@SSL``` after the ```.com``` but I got "Could not resolve host: SSL" error – DJL May 15 '20 at 19:46