I have valid access token to Dropbox account (API v2), Delphi 7 and, Indy 10. When I try to use this token I have exception 'HTTP/1.1 400 Bad Request'. I look at Dropbox API v2 and can't understand: what's wrong with the request?
procedure TDropboxSaveFilterForm.TestButtonClick(Sender: TObject);
const
AccessToken = 'Hq7XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var
IdHTTP: TIdHTTP;
Source: TStringList;
Res, URL: WideString;
begin
Source := TStringList.Create;
IdHTTP := TIdHTTP.Create(nil);
IdHTTP.IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(IdHTTP);
URL := 'https://api.dropboxapi.com/2/files/list_folder' + '?' +
'Authorization=Bearer ' + AccessToken;
Res := IdHTTP.Post(URL, Source);
Source.Free;
end;
New code with the header, error the same :-(. According to Indy: Request Specifies the header values to send to the HTTP server.
procedure TDropboxSaveFilterForm.TestHeaderButtonClick(Sender: TObject);
const
AccessToken = 'Hq7XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
URL = 'https://api.dropboxapi.com/2/files/list_folder';
var
IdHTTP: TIdHTTP;
Source: TStringList;
Head, Res: WideString;
Stream: TMemoryStream;
begin
Source := TStringList.Create;
IdHTTP := TIdHTTP.Create(nil);
IdHTTP.IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(IdHTTP);
Head := 'Authorization: Bearer ' + AccessToken;
Stream := TMemoryStream.Create;
Stream.Write(Head, Length(Head));
Stream.Position := 0;
IdHTTP.Request.Source := Stream;
Res := IdHTTP.Post(URL, Source);
Source.Free;
end;
codeHead := 'Authorization: Bearer ' + AccessToken; Stream := TMemoryStream.Create; Stream.Write(Head, Length(Head)); Stream.Position := 0; IdHTTP.Request.Source := Stream; Res := IdHTTP.Post(URL, Source);codeand have no success. Maybe you have an working example? - Oleg Adibekov