X.com Verfiy Credentials (Deprecated OAuth 1.0a Authentication)
See more X Examples
This is a simple API call to verify that OAuth1.0a authorization is working.Returns an HTTP 200 OK response code and a representation of the requesting user if authentication was successful; returns a 401 status code and an error message if not. Use this method to test if supplied user credentials are valid.
X.com historically used OAuth 1.0a for authenticating API requests. However, as of April 2023, Twitter has deprecated OAuth 1.0a and migrated to OAuth 2.0 for most of its API endpoints. This change was part of Twitter's effort to modernize its API and improve security.
That said, if you're working with a legacy system or have access to older documentation, you might still encounter references to OAuth 1.0a.
This example shows how Chilkat could be used with the older/deprecated Twitter v1.1 API calls.
Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Http,
Chilkat.StringBuilder,
Chilkat.JsonObject;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
http: THttp;
sbResponse: TStringBuilder;
statusCode: Integer;
json: TJsonObject;
begin
success := False;
http := THttp.Create;
// Indicate OAuth1.0a authentication is to be used with HTTP requests.
http.OAuth1 := True;
// Provide OAuth1.0a credentials
http.OAuthConsumerKey := 'X_API_KEY';
http.OAuthConsumerSecret := 'X_API_SECRET';
http.OAuthSigMethod := 'HMAC-SHA1';
http.OAuthToken := 'X_ACCESS_TOKEN';
http.OAuthTokenSecret := 'X_TOKEN_SECRET';
http.OAuthVerifier := '';
sbResponse := TStringBuilder.Create;
success := http.QuickGetSb('https://api.twitter.com/1.1/account/verify_credentials.json',sbResponse);
if (success = False) then
begin
WriteLn(http.LastErrorText);
Exit;
end;
statusCode := http.LastStatus;
if (statusCode <> 200) then
begin
WriteLn(http.LastErrorText);
Exit;
end;
// We received a successful JSON response.
json := TJsonObject.Create;
json.LoadSb(sbResponse);
json.EmitCompact := False;
WriteLn(json.Emit());
http.Free;
sbResponse.Free;
json.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.