![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java JavaScript Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(SQL Server) Twitter PIN-Based Authorization (Step 2)Demonstrates the 2nd step in Twitter PIN-based authorization using OAuth. A PIN should have already been obtained from Step 1. The PIN is the OAuth verifier used in combination with the consumer secret and consumer key to get the access token and token secret that will be used for subsequent Twitter requests (to do whatever the Twitter account owner has permitted your application to do..) Note: This example requires Chilkat v11.0.0 or greater.
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls. -- CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @iTmp0 int -- Important: Do not use nvarchar(max). See the warning about using nvarchar(max). DECLARE @sTmp0 nvarchar(4000) DECLARE @success int SELECT @success = 0 -- This example requires the Chilkat API to have been previously unlocked. -- See Global Unlock Sample for sample code. DECLARE @http int EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END EXEC sp_OASetProperty @http, 'OAuth1', 1 EXEC sp_OASetProperty @http, 'OAuthConsumerKey', 'my-consumer-key' EXEC sp_OASetProperty @http, 'OAuthConsumerSecret', 'my-consumer-secret' EXEC sp_OASetProperty @http, 'OAuthVerifier', 'the-PIN-obtained-from-Step1' DECLARE @req int EXEC @hr = sp_OACreate 'Chilkat.HttpRequest', @req OUT EXEC sp_OASetProperty @req, 'HttpVerb', 'POST' EXEC sp_OASetProperty @req, 'ContentType', 'application/x-www-form-urlencoded' DECLARE @resp int EXEC @hr = sp_OACreate 'Chilkat.HttpResponse', @resp OUT EXEC sp_OAMethod @http, 'HttpReq', @success OUT, 'https://api.twitter.com/oauth/access_token', @req, @resp IF @success = 0 BEGIN EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @req EXEC @hr = sp_OADestroy @resp RETURN END EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT IF @iTmp0 = 200 BEGIN -- Get the access token and secret: DECLARE @oauthToken nvarchar(4000) EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT EXEC sp_OAMethod @resp, 'UrlEncParamValue', @oauthToken OUT, @sTmp0, 'oauth_token' PRINT 'Access token = ' + @oauthToken DECLARE @oauthTokenSecret nvarchar(4000) EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT EXEC sp_OAMethod @resp, 'UrlEncParamValue', @oauthTokenSecret OUT, @sTmp0, 'oauth_token_secret' PRINT 'Token secret = ' + @oauthTokenSecret -- Your application may now perform operations on the -- Twitter account for whatever has been authorized. -- To do so, prior to sending the HTTP request, -- set the OAuthToken and OAuthTokenSecret -- properties, and also make sure to clear OAuthVerifier property: EXEC sp_OASetProperty @http, 'OAuthToken', @oauthToken EXEC sp_OASetProperty @http, 'OAuthTokenSecret', @oauthTokenSecret EXEC sp_OASetProperty @http, 'OAuthVerifier', '' -- Now that the http object has valid property values -- for OAuthConsumerKey, OAuthConsumerSecret, -- OAuthToken, and OAuthTokenSecret, it can send authenticated -- Twitter requests to the user's Twitter account. END ELSE BEGIN EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 END EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @req EXEC @hr = sp_OADestroy @resp END GO |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.