Terenz Posted October 1, 2016 Posted October 1, 2016 (edited) Hello, I want to know the metadata of a file ConsoleWrite(_Dropbox_v1("YOUR_AUTH", "/File.txt") & @CRLF) ConsoleWrite(_Dropbox_v2("YOUR_AUTH", "/File.txt") & @CRLF) Func _Dropbox_v1($sAccessToken, $sPath = "") $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1") $oHTTP.Open("GET", "https://api.dropbox.com/1/metadata/auto/" & $sPath, False) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded;") $oHTTP.SetRequestHeader("Authorization", "Bearer " & $sAccessToken) $oHTTP.Send() $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status If ($oStatusCode <> 200) Then Return $oHTTP.ResponseText Return SetError(1, 0, $oHTTP.ResponseText) EndFunc ;==>_Dropbox_v1 Func _Dropbox_v2($sAccessToken, $sPath = "") $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1") $oHTTP.Open("POST", "https://api.dropbox.com/2/files/get_metadata", False) $oHTTP.SetRequestHeader("Content-Type", "text/plain; charset=dropbox-cors-hack") $oHTTP.SetRequestHeader("Authorization", "Bearer " & $sAccessToken) $oHTTP.Send() $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status If ($oStatusCode <> 200) Then Return $oHTTP.ResponseText Return SetError(1, 0, $oHTTP.ResponseText) EndFunc ;==>_Dropbox_v2 The first version work fine but: As of today, Dropbox API v1 is deprecated...we’ll be turning off API v1 a year from now, on 6/28/2017 So i need to make it work with v2. API v1 → v2 Migration guide: https://www.dropbox.com/developers/reference/migration-guide I'm intrestend in only: /1/metadata --> /2/files/get_metadata https://www.dropbox.com/developers/documentation/http/documentation#files-get_metadata The error i have is: Error in call to API function "files/get_metadata": request body: could not decode input as JSON Searching around i have found this: Quote Finally! this worked for me: return Parse.Cloud.httpRequest({ method: 'POST', url: 'https://api.dropboxapi.com/2/users/get_current_account', headers: { 'Content-Type': 'application/json; charset=utf-8', 'Authorization': 'Bearer ' + newAccessToken }, body: JSON.stringify(null) }); I had to use JSON.stringify(null) in the body. I don't know the alternative to "stringify" in autoit. An help? Thanks Edited October 1, 2016 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength
genius257 Posted October 1, 2016 Posted October 1, 2016 (edited) 59 minutes ago, Terenz said: I don't know the alternative to "stringify" in autoit. An help? Thanks stringify just returns the string representation of the object you out in the parameter. Doing " JSON.stringify(null)" in the console in firefox returns "null", i would also suggest doing "{}" if it's simply an empty object you wish to parse Edit: I also noticed the $sPath is not being used by the function in v2. This is how it should work now (yes i know it would be better to verify the characters in the $spath apply to the content rules of a URL syntax) Func _Dropbox_v2($sAccessToken, $sPath = "") $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1") $oHTTP.Open("POST", "https://api.dropbox.com/2/files/get_metadata", False) $oHTTP.SetRequestHeader("Content-Type", "text/plain; charset=dropbox-cors-hack") $oHTTP.SetRequestHeader("Authorization", "Bearer " & $sAccessToken) $oHTTP.Send('{"path":"'&$sPath&'"}') $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status If ($oStatusCode <> 200) Then Return $oHTTP.ResponseText Return SetError(1, 0, $oHTTP.ResponseText) EndFunc ;==>_Dropbox_v2 Edit2: Also, I'm happy you upload an example to run without extra work, however i suspect the accessTokens are private keys referring all activity to you? Maybe keep them for yourself Edited October 1, 2016 by genius257 To show your appreciation My highlighted topics: AutoIt Package Manager, AutoItObject Pure AutoIt, AutoIt extension for Visual Studio Code Github: AutoIt HTTP Server, AutoIt HTML Parser
Terenz Posted October 1, 2016 Author Posted October 1, 2016 (edited) 33 minutes ago, genius257 said: Also, I'm happy you upload an example to run without extra work, however i suspect the accessTokens are private keys referring all activity to you? Maybe keep them for yourself Don't worry about AccessTokens. Yes there are key referring to an account but i have created that account just for this thread with only 1 file, i'll delete it since i'm solve this. Path with v1 was optional parameter, with v2 seems not...stupid mistake. Thanks Edited October 1, 2016 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength
genius257 Posted October 1, 2016 Posted October 1, 2016 1 minute ago, Terenz said: Seems correct but not work. Thanks There's a backslash before the ". normally the string would close, but the backslash escapes the character and boom! syntax error. Simply remove the backslash like so: $oHTTP.Send('{"path":"'&$sPath&'","include_media_info": false}') To show your appreciation My highlighted topics: AutoIt Package Manager, AutoItObject Pure AutoIt, AutoIt extension for Visual Studio Code Github: AutoIt HTTP Server, AutoIt HTML Parser
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now