![]() |
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
(Delphi DLL) Twitter PIN-Based Authorization (Step 1)Demonstrates the 1st step in Twitter PIN-based authorization using OAuth. The purpose of this step is to obtain a temporary request token that will be traded for an access token + secret in the final step. Once the access token + secret is obtained, the application can access the Twitter account in whatever ways it was authorized. Note: This example requires Chilkat v11.0.0 or greater.
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Http, HttpRequest, HttpResponse; ... procedure TForm1.Button1Click(Sender: TObject); var success: Boolean; http: HCkHttp; req: HCkHttpRequest; resp: HCkHttpResponse; oauthToken: PWideChar; oauthTokenSecret: PWideChar; oauthCbConfirmed: PWideChar; begin success := False; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http := CkHttp_Create(); CkHttp_putOAuth1(http,True); CkHttp_putOAuthConsumerKey(http,'my-consumer-key'); CkHttp_putOAuthConsumerSecret(http,'my-consumer-secret'); req := CkHttpRequest_Create(); CkHttpRequest_putHttpVerb(req,'POST'); CkHttpRequest_putContentType(req,'application/x-www-form-urlencoded'); resp := CkHttpResponse_Create(); success := CkHttp_HttpReq(http,'https://api.twitter.com/oauth/request_token',req,resp); if (success = False) then begin Memo1.Lines.Add(CkHttp__lastErrorText(http)); Exit; end; if (CkHttpResponse_getStatusCode(resp) = 200) then begin oauthToken := CkHttpResponse__urlEncParamValue(resp,CkHttpResponse__bodyStr(resp),'oauth_token'); Memo1.Lines.Add('OAuth temporary request token = ' + oauthToken); oauthTokenSecret := CkHttpResponse__urlEncParamValue(resp,CkHttpResponse__bodyStr(resp),'oauth_token_secret'); Memo1.Lines.Add('OAuth temporary token secret = ' + oauthTokenSecret); oauthCbConfirmed := CkHttpResponse__urlEncParamValue(resp,CkHttpResponse__bodyStr(resp),'oauth_callback_confirmed'); Memo1.Lines.Add('OAuth callback confirmed = ' + oauthCbConfirmed); // At this point, the end-user needs to browse to the following // Twitter URL to log in to his/her Twitter account and get a PIN. // // https://api.twitter.com/oauth/authenticate?oauth_token=OAUTH_TOKEN // // (where OAUTH_TOKEN is replaced with the contents // of the OAuth temporary request token.) // Your application may have an embedded browser such // that it automatically navigates to the above URL, or it may // be necessary for the user to browse to this URL independently. // Once the PIN is obtained, your application should provide a means // for the end-user to enter it (by typing it into an input text box, for example), // and then Step 2 (the final step) can begin. end else begin Memo1.Lines.Add(CkHttp__lastErrorText(http)); end; CkHttp_Dispose(http); CkHttpRequest_Dispose(req); CkHttpResponse_Dispose(resp); end; |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.