簡體   English   中英

使用 Windows 身份驗證訪問 R 中的共享點

[英]Accessing sharepoint in R with windows authentication

我正在嘗試從我公司的內部網共享點讀取數據。

require(httr)
url <- "http://<domain>/<path>/_vti_bin/ListData.svc/<something>"
r <- GET(url)

問題是,對 Sharepoint 的訪問使用 Windows 身份驗證。 預期以上內容給了我 401 Unauthorized 錯誤。

如何將我的 Windows 身份驗證合並到 R 中的請求中,而無需在GET參數中以明文形式鍵入我的憑據? (使用帶有我的憑據的authenticate()確實有效)。

authenticate()是正確使用的函數,但您需要更改輸入,如下所示:

require(httr)
url <- "http://<domain>/<path>/_vti_bin/ListData.svc/<something>"
r <- GET(url, authenticate("username","password",type="any"))

我不確定哪種特定類型有效,但我能夠使用 any 建立會話。 我在 httr 包文檔中找到了解決方案。

https://cran.r-project.org/web/packages/httr/httr.pdf

獲取此處概述的站點 ID。 獲取此處概述的列表 ID。 如果您需要擴展任何列表項,請查看此內容

並且為了確保您不會像我一樣脫發和禿頂,請確保您在 SharePoint 網站中讀取訪問的項目級權限設置為“讀取所有項目”( 這里是參考)。

library(AzureGraph)

gr <- create_graph_login()
me <- gr$get_user("me")
url <- "https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items"
r <- call_graph_url(me$token, url, http_verb = c("GET"))

如果身份驗證對您有用,並且您的主要目標是不讓您的用戶和密碼硬編碼並在腳本中公開,請嘗試使用包 getPass,它有一個名為 getPass(msg="message you want to display") 的函數,它打開一個提示,讓您輸入一個字符串(對於觀看您屏幕的任何人都被屏蔽),然后返回該字符串。

免責聲明:如果您這樣做,則運行腳本的任何人都必須具有安全訪問權限並輸入他們自己的憑據才能使腳本工作。 此外,如果您在 RStudio 之類的東西中工作,其中您的環境顯示在側面板中,則這些值將暴露給任何從您身后看的人:

require(httr)
require(getPass)

user <- getPass(msg="Enter User ID: ")
pw <- getPass(msg="Enter password: ")

url <- "http://<domain>/<path>/_vti_bin/ListData.svc/<something>"
r <- GET(url, authenticate(user,pw,type="any"))

我能夠使用RCurlXML包中的函數組合來驗證我的會話並將 SharePoint 列表轉換為數據RCurl 這是唯一對我有效的方法。

library(RCurl)
library(XML)
URL = "http://<domain>/<path>/_vti_bin/ListData.svc/<something>"
rawData = getURL(URL,userpwd=:"username:password")
xmlData = xmlParse(rawData)
items = getNodeSet(xmlData,"//m:properties")
df = xmlToDataFrame(items,stringsAsFactors=F)

如果在使用 Windows 身份驗證的公司網絡上,則無需鍵入用戶名和密碼即可執行以下操作:

library(httr)

url <- "http://<domain>/<path>/_vti_bin/ListData.svc/<something>"
r <- GET(url, authenticate(":", ":", "ntlm"))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM