Created
October 16, 2023 05:54
-
-
Save DelphiWorlds/e49d31e9fd798f7344eac6331d339b72 to your computer and use it in GitHub Desktop.
Get OAuth2 Access Token from Twitter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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