Chilkat HOME Android™ Classic ASP C C++ C# Mono C# .NET Core C# C# UWP/WinRT DataFlex Delphi ActiveX Delphi DLL Visual FoxPro Java Lianja MFC Objective-C Perl PHP ActiveX PHP Extension PowerBuilder PowerShell PureBasic CkPython Chilkat2-Python Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ Visual Basic 6.0 VB.NET VB.NET UWP/WinRT VBScript Xojo Plugin Node.js Excel Go
(MFC) 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: The OAuth version 1 functionality demonstrated in this example is available in Chilkat v9.4.0 to be released approximately in mid-December 2012. Pre-releases are available upon request by sending email to support@chilkatsoft.com. (Please be sure to specify your programming language, operating system, framework, architecture, etc. to uniquely identify the build that is needed.)
#include <CkHttp.h> #include <CkHttpRequest.h> #include <CkHttpResponse.h> void ChilkatSample(void) { CkString strOut; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkHttp http; http.put_OAuth1(true); http.put_OAuthConsumerKey("my-consumer-key"); http.put_OAuthConsumerSecret("my-consumer-secret"); CkHttpRequest req; CkHttpResponse *resp = http.PostUrlEncoded("https://api.twitter.com/oauth/request_token",req); if (http.get_LastMethodSuccess() == false) { strOut.append(http.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } if (resp->get_StatusCode() == 200) { const char *oauthToken = resp->urlEncParamValue(resp->bodyStr(),"oauth_token"); strOut.append("OAuth temporary request token = "); strOut.append(oauthToken); strOut.append("\r\n"); const char *oauthTokenSecret = resp->urlEncParamValue(resp->bodyStr(),"oauth_token_secret"); strOut.append("OAuth temporary token secret = "); strOut.append(oauthTokenSecret); strOut.append("\r\n"); const char *oauthCbConfirmed = resp->urlEncParamValue(resp->bodyStr(),"oauth_callback_confirmed"); strOut.append("OAuth callback confirmed = "); strOut.append(oauthCbConfirmed); strOut.append("\r\n"); // 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. } else { strOut.append(http.lastErrorText()); strOut.append("\r\n"); } delete resp; SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); } |
||||
© 2000-2022 Chilkat Software, Inc. All Rights Reserved.