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 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: 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"); http.put_OAuthVerifier("the-PIN-obtained-from-Step1"); CkHttpRequest req; CkHttpResponse *resp = http.PostUrlEncoded("https://api.twitter.com/oauth/access_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) { // Get the access token and secret: const char *oauthToken = resp->urlEncParamValue(resp->bodyStr(),"oauth_token"); strOut.append("Access token = "); strOut.append(oauthToken); strOut.append("\r\n"); const char *oauthTokenSecret = resp->urlEncParamValue(resp->bodyStr(),"oauth_token_secret"); strOut.append("Token secret = "); strOut.append(oauthTokenSecret); strOut.append("\r\n"); // 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: http.put_OAuthToken(oauthToken); http.put_OAuthTokenSecret(oauthTokenSecret); http.put_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. } else { strOut.append(http.lastErrorText()); strOut.append("\r\n"); } delete resp; SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); } |
||||
© 2000-2022 Chilkat Software, Inc. All Rights Reserved.