api from vb .net for windows desktop app
Hi. I'm developing a windows desktop app in order to get the dropbox links of the files inside my dropbox directory. I want to use the 'create_shared_link_with_settings' Dropbox api but when I execute POST method I only get vb exception: 'HTTP Error 400 Bad request'.
I'm a basic Dropbox user and developing app for personal use (I don't need to enable additional users). I registered my app and got OAuth2 token.
The data I'm sending is:
{"path":"/Public/MyFile.pdf","settings":{"requested_visibility":"public"}}
In the headers:
"Authorization: Bearer myOAuth2TokenHere"
And the url: "https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings"
Here is the vb .net [FrameWork 4.0] code I'm using.
Dim sFormattedFilePath As String = ""
Dim sUri As String = ""
Dim sData As String = ""
Dim sJSON As String = ""
Dim pHeader As WebHeaderCollection = Nothing
Dim pRequest As HttpWebRequest = Nothing
Dim pResponse As HttpWebResponse = Nothing
Try
sFormattedFilePath = "/Public/MyFile.pdf"
sData = "{" & Chr(34) & "path" & Chr(34) & ":" & Chr(34) & sFormattedFilePath & Chr(34) & "," & Chr(34) & "settings" & Chr(34) & ":{" & Chr(34) & "requested_visibility" & Chr(34) & ":" & Chr(34) & "public" & Chr(34) & "}}"
pHeader = New WebHeaderCollection()
pHeader.Clear()
pHeader.Add("Authorization: Bearer myOAuth2TokenHere")
sUri = "https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings"
pRequest = DirectCast(HttpWebRequest.Create(sUri), HttpWebRequest)
pRequest.ContentType = "application/json"
pRequest.ContentLength = sData.Length
pRequest.Headers = pHeader
pRequest.Method = "POST"
Using s As Stream = pRequest.GetRequestStream()
s.Write(System.Text.ASCIIEncoding.Default.GetBytes(sData), 0, sData.Length)
End Using
pResponse = DirectCast(pRequest.GetResponse(), HttpWebResponse)
Using sr As New StreamReader(pResponse.GetResponseStream())
sJSON = sr.ReadToEnd()
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try
If you are wondering:
The content of var sData is
{"path":"/Public/MyFile.pdf","settings":{"requested_visibility":"public"}}
The exception occurs when executing line:
pResponse = DirectCast(pRequest.GetResponse(), HttpWebResponse)
And the message of exception is:
HTTP Error 400 Bad request
I used exactly the same vb.net code when calling 'get_shared_links' api and it worked fine, that's why I was sure the code was correct but when I call 'create_shared_link_with_settings' the code doesn't work.
Any clue of what's happening?? please Help :'(