uses [...], EncdDecd, IdHttp, IdSSLOpenSSL;
Const
ConsumerKey:
String = '
xvz1evFS4wEEPTGEFPHBog';
{Beispiel von Twitter}
ConsumerSecret:
String = '
L8qq9PZyRg6ieKGEKhZolGC0vJWLw8iEJ88DRdyOg';
{Beispiel von Twitter}
Function EncodeBase64(Input:
String):
String;
Var
fstream, fStringStream: TStringStream;
Begin
fstream := TStringStream.Create(Input);
fStringStream := TStringStream.create('
');
EncodeStream(fstream, fStringStream);
Result := fStringStream.DataString;
End;
procedure TForm1.Button1Click(Sender: TObject);
Var
Credentials:
String;
MyHTTP: TIdHTTP;
Result: TMemoryStream;
begin
Credentials := EncodeBase64(ConsumerKey + '
:' + ConsumerSecret);
MyHTTP := TIdHTTP.Create(
nil);
With MyHttp
do
Begin
Request.Host := '
api.twitter.com/';
Request.CustomHeaders.Add('
Authorization: Basic ' + Credentials);
Request.ContentType := '
application/x-www-form-urlencoded;charset=UTF-8';
Request.CustomHeaders.Add('
grant_type=client_credentials');
IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(
nil);
Result := TMemoryStream.Create;
Post('
https://api.twitter.com/oauth/request_token', Result);
Memo1.Lines.LoadFromStream(Result);
FreeAndNil(Result);
End;
MyHttp.Free;
end;