C#
C#
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.Chilkat C# Downloads
bool success = false;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Chilkat.Http http = new Chilkat.Http();
http.OAuth1 = true;
http.OAuthConsumerKey = "my-consumer-key";
http.OAuthConsumerSecret = "my-consumer-secret";
Chilkat.HttpRequest req = new Chilkat.HttpRequest();
req.HttpVerb = "POST";
req.ContentType = "application/x-www-form-urlencoded";
Chilkat.HttpResponse resp = new Chilkat.HttpResponse();
success = http.HttpReq("https://api.twitter.com/oauth/request_token",req,resp);
if (success == false) {
Debug.WriteLine(http.LastErrorText);
return;
}
if (resp.StatusCode == 200) {
string oauthToken = resp.UrlEncParamValue(resp.BodyStr,"oauth_token");
Debug.WriteLine("OAuth temporary request token = " + oauthToken);
string oauthTokenSecret = resp.UrlEncParamValue(resp.BodyStr,"oauth_token_secret");
Debug.WriteLine("OAuth temporary token secret = " + oauthTokenSecret);
string oauthCbConfirmed = resp.UrlEncParamValue(resp.BodyStr,"oauth_callback_confirmed");
Debug.WriteLine("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 {
Debug.WriteLine(http.LastErrorText);
}