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 SQL Server Downloads
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
DECLARE @http int
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- Indicate OAuth1.0a authentication is to be used with HTTP requests.
EXEC sp_OASetProperty @http, 'OAuth1', 1
-- Provide OAuth1.0a credentials
EXEC sp_OASetProperty @http, 'OAuthConsumerKey', 'X_API_KEY'
EXEC sp_OASetProperty @http, 'OAuthConsumerSecret', 'X_API_SECRET'
EXEC sp_OASetProperty @http, 'OAuthSigMethod', 'HMAC-SHA1'
EXEC sp_OASetProperty @http, 'OAuthToken', 'X_ACCESS_TOKEN'
EXEC sp_OASetProperty @http, 'OAuthTokenSecret', 'X_TOKEN_SECRET'
EXEC sp_OASetProperty @http, 'OAuthVerifier', ''
DECLARE @sbResponse int
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponse OUT
EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, 'https://api.twitter.com/1.1/account/verify_credentials.json', @sbResponse
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponse
RETURN
END
DECLARE @statusCode int
EXEC sp_OAGetProperty @http, 'LastStatus', @statusCode OUT
IF @statusCode <> 200
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponse
RETURN
END
-- We received a successful JSON response.
DECLARE @json int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'LoadSb', @success OUT, @sbResponse
EXEC sp_OASetProperty @json, 'EmitCompact', 0
EXEC sp_OAMethod @json, 'Emit', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponse
EXEC @hr = sp_OADestroy @json
END
GO