Huynhnhi92

DopboxAPI Download

Sep 19th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 1.17 KB | None | 0 0
  1.  
  2.     $access_token = "token*********"
  3.                     ;$uid = 470341585
  4.                     $file_path = @ScriptDir&"\dropbox.zip"
  5.                     $file_content = FileRead($file_path)
  6.                     $file_handle = FileOpen($file_path,16)
  7.                     $file_binary = FileRead($file_handle)
  8.  
  9.                     Dropboxapi_oathv2_download("/dropbox.zip",$file_binary,$access_token)
  10.  
  11. Func Dropboxapi_oathv2_download($path,$binary,$access_token,$token_type="Bearer")
  12.    Local $apiUrl = "https://content.dropboxapi.com/2/files/download"
  13.    Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
  14.    $oHTTP.Open("POST", $apiUrl, False)
  15.    $oHTTP.SetRequestHeader("Authorization", $token_type & " "  & $access_token)
  16.    $oHTTP.SetRequestHeader("Dropbox-API-Arg", '{"path": "' & $path & '" }')
  17.    $oHTTP.Send($file_content)
  18.    Local $oReceived = $oHTTP.ResponseText
  19.    Local $oStatusCode = $oHTTP.Status
  20.    If $oStatusCode = 200 Then
  21.           ConsoleWrite("$Received:" & $oReceived & @CRLF)
  22.           Return $oReceived
  23.    Else
  24.           ConsoleWrite("$Received:" & $oReceived & @CRLF & "Error:" & $oStatusCode & @CRLF)
  25.           SetError($oStatusCode)
  26.    EndIf
  27. EndFunc
Add Comment
Please, Sign In to add comment