VBA POST请求超时

时间:2019-12-02 23:05:38

标签: excel vba rest oauth-2.0 sharepoint-online

我正在尝试使用VBA将列表项添加到SharePoint Online列表。多年来,我一直成功使用SharePoint 2013进行此操作,但是向云的过渡导致我遇到问题。特别是身份验证过程。我正在尝试使用Here

中概述的过程

这可以在我的浏览器中使用REST客户端运行,但是我无法从Excel VBA中使用它。当我尝试在VBA中进行POST时,它会锁定程序(Excel)几分钟,然后我收到一个错误,表明请求超时。任何帮助将不胜感激。


ClientID = "<my client id>"
ClientSecret = "<my client secret>"
Principle = "<my principle>"
myRealm = "<my realm>"
Resource = Principle & "/mySite.sharepoint.com@" & myRealm

Dim objHTTP As Object
Set objHTTP = CreateObject("MSXML2.serverXMLHTTP") 

grantString = "grant_type=" & "client_credentials"
clientIDString = "client_id=" & WorksheetFunction.EncodeURL(ClientID)
clientScrtString = "client_secret=" & WorksheetFunction.EncodeURL(ClientSecret)
resourceString = "resource=" & WorksheetFunction.EncodeURL(Resource)

body = grantString & "&" & clientIDString & "&" & clientScrtString & "&" & resourceString

urlEndPoint = "https://accounts.accesscontrol.windows.net/" & WorksheetFunction.EncodeURL(myRealm) & "/tokens/OAuth/2"

With objHTTP
    .Open "POST", urlEndPoint, False
    .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    .send body 
End With

0 个答案:

没有答案