How to use curl for Dropbox token in Firemonkey

  

I’m trying to get Dropbox token base on Dropbox documentation.

For that I have to use (from Dropbox documentation):
https://www.dropbox.com/developers/documentation/http/documentation#oauth2-token

URL: https://api.dropboxapi.com/oauth2/token

METHOD: POST

EXAMPLE:
curl https://api.dropbox.com/oauth2/token \
-d code=<AUTHORIZATION_CODE> \
-d grant_type=authorization_code \
-d redirect_uri=<REDIRECT_URI> \
-u <APP_KEY>:<APP_SECRET>

But I don’t know how to do that in Firemonkey. I was trying to do something like that but without success.

My code:

HTTP := TIdHTTP.Create(nil);
try
HTTP.HandleRedirects := True;
HTTP.ConnectTimeout := FHTTPTimeout;
HTTP.Request.BasicAuthentication := False;
HTTP.IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(HTTP);
HTTP.Request.Accept := ‘application/x-www-form-urlencoded’;
HTTP.Request.ContentType := ‘application/json’;

sTemp:= ‘{ “code”=”<‘ + Settings.SynchroDropBoxCode + ‘>” ‘ + keyCrLf +
‘ “grant_type”=”authorization_code” ‘ + keyCrLf +
‘ “redirect_uri”=”<http://127.0.0.1:8888/>” ‘ + keyCrLf +
‘ “<‘ + cloudDropBoxMobileAppKey + ‘>”:”<‘+cloudDropBoxMobileAppKeySecret+’>” }’;

DataToSend := TStringStream.Create(sTemp, TEncoding.UTF8, True);
try
sHTTPResponse := HTTP.Post(‘https://api.dropbox.com/oauth2/token’, DataToSend);
finally
DataToSend.Free;
end;
finally
HTTP.Free;
end;

Comments are closed.