![]() |
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
(Android™) 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.
// Important: Don't forget to include the call to System.loadLibrary // as shown at the bottom of this code sample. package com.test; import android.app.Activity; import com.chilkatsoft.*; import android.widget.TextView; import android.os.Bundle; public class SimpleActivity extends Activity { private static final String TAG = "Chilkat"; // Called when the activity is first created. @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); boolean success = false; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkHttp http = new CkHttp(); http.put_OAuth1(true); http.put_OAuthConsumerKey("my-consumer-key"); http.put_OAuthConsumerSecret("my-consumer-secret"); CkHttpRequest req = new CkHttpRequest(); req.put_HttpVerb("POST"); req.put_ContentType("application/x-www-form-urlencoded"); CkHttpResponse resp = new CkHttpResponse(); success = http.HttpReq("https://api.twitter.com/oauth/request_token",req,resp); if (success == false) { Log.i(TAG, http.lastErrorText()); return; } if (resp.get_StatusCode() == 200) { String oauthToken = resp.urlEncParamValue(resp.bodyStr(),"oauth_token"); Log.i(TAG, "OAuth temporary request token = " + oauthToken); String oauthTokenSecret = resp.urlEncParamValue(resp.bodyStr(),"oauth_token_secret"); Log.i(TAG, "OAuth temporary token secret = " + oauthTokenSecret); String oauthCbConfirmed = resp.urlEncParamValue(resp.bodyStr(),"oauth_callback_confirmed"); Log.i(TAG, "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. } else { Log.i(TAG, http.lastErrorText()); } } static { System.loadLibrary("chilkat"); // Note: If the incorrect library name is passed to System.loadLibrary, // then you will see the following error message at application startup: //"The application <your-application-name> has stopped unexpectedly. Please try again." } } |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.