Skip to content

Instantly share code, notes, and snippets.

@DelphiWorlds
Created October 16, 2023 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DelphiWorlds/e49d31e9fd798f7344eac6331d339b72 to your computer and use it in GitHub Desktop.
Save DelphiWorlds/e49d31e9fd798f7344eac6331d339b72 to your computer and use it in GitHub Desktop.
Get OAuth2 Access Token from Twitter
const
cAuth = 'YourKeyAndSecret';
procedure TForm1.Button1Click(Sender: TObject);
var
LHTTP: THTTPClient;
LResponse: IHTTPResponse;
LContent: TStream;
LBase64: TBase64Encoding;
begin
LHTTP := THTTPClient.Create;
try
LHTTP.ContentType := 'application/x-www-form-urlencoded';
LBase64 := TBase64Encoding.Create(0, '');
try
LHTTP.CustomHeaders['Authorization'] := 'Basic ' + LBase64.Encode(cAuth);
finally
LBase64.Free;
end;
LContent := TStringStream.Create('grant_type=client_credentials');
try
LResponse := LHTTP.Post('https://api.twitter.com/oauth2/token', LContent);
finally
LContent.Free;
end;
finally
LHTTP.Free;
end;
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment