有谁知道是否有使用 Visual Basic 连接到 Box.com 文档的示例代码?
我们有一些精心制作的 VB Excel 宏,可以从各种文件中提取数据。现在我们已经切换到使用 box.com 作为我们的文件系统,我们希望这些宏能够读取/写入存储在 Box.com 中的文件所需的数据。
以下是将 VBScript 中的文件上传到 Box 的一些示例代码:
api_key = "Your API key from Box.net"
BoxNetUserName = "Your Box.net username"
BoxNetPwd = "Your Box.net Password"
UploadFileBoxNet("c:\coupons.pdf")
Function UploadFileBoxNet(filePath)
Print filepath
Set WinHttpReq = CreateObject("Msxml2.ServerXMLHTTP")
'**********Requesting Ticket
strURL = "https://www.box.net/api/1.0/rest?action=get_ticket&api_key=" & api_key
temp = WinHttpReq.Open("POST", strURL, false)
WinHttpReq.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
WinHttpReq.Send()
getTicket = WinHttpReq.ResponseText
Print strURL
Print getTicket
'**********Extracting Ticket from XML Response********
getTicket = Left(getTicket,Len(getTicket)-20)
getTicket = Right(getTicket,Len(getTicket) - Instr(getTicket,"t>")-1)
Print getTicket
'****Opening Authentication Window for Box.net********
Systemutil.Run "iexplore", "https://www.box.net/api/1.0/auth/" & getTicket
Browser("name:=Box.net.*").WebEdit("name:=login").Set BoxNetUserName
Browser("name:=Box.net.*").WebEdit("name:=password").Set BoxNetPwd
Browser("name:=Box.net.*").WebElement("name:=Login","height:=25").Click
Browser("name:=Box.net.*").Sync
Browser("name:=Box.net.*").Close
'*****Requesting Auth_Token
strUrl = "https://www.box.net/api/1.0/rest?action=get_auth_token&api_key=" api_key & "&ticket=" & getTicket
temp = WinHttpReq.Open("POST", strURL, false)
WinHttpReq.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
WinHttpReq.Send()
Auth_Token = WinHttpReq.ResponseText
Print strURL
'******Parsing Auth Token from XML Response
Set xmlObj = XMLUtil.CreateXML()
xmlObj.Load Auth_Token
Print xmlObj.ToString()
Print " ========================================================================= "
Set myToken = xmlObj.ChildElementsByPath("/response/auth_token")
Print myToken.Count
For i = 1 to myToken.Count
Auth_Token = myToken.Item(i).Value()
Print Auth_Token
Print " "
Next
strURL = "https://upload.box.net/api/1.0/upload/" & Auth_Token & "/0"
'*****Calling the Upload File method of the .Net Class System.Net.WebClient
Set wcl = DotNetFactory.CreateInstance ("System.Net.WebClient")
strResult = wcl.UploadFile(strURL, filepath)
End Function