Description

OAuthAccess is OAuth Library For Net Framework 3.5 ClientProfile .
License is MS-PL.

This Library can build Request flexibility.

Supported proxy.
Supported Auto retry that it has specific condition,

About detail,please show Documentaition.
All documents were written by English(poor...)

Sample

it contains two sample project.
  1. Simple TwitterAccessConsoleApplication(GetRequestToken~GetHomeTimeLine And PostTweet)
  2. Simple TwitpicUploaderByOAuthEchoConsoleApplication(GetRequestToken~Upload~ShowUploadUrl)

Example Usage

Get Twitter HomeTimeLine

var result = OAuthRequest.Create(consumer, accessToken)
                .SetHttpMethod(HttpMethodType.Get)
                .SetUrl("http://api.twitter.com/1/statuses/home_timeline.xml")
                .CommitRequest()
                .GetResponse()
                .ParseToXElement();

var text = from e in result.Descendants("status")
           select
           s.Element("user").Element("screen_name").Value +
           " : " +
           s.Element("text").Value;

Tweet

string postText = Console.In.ReadLine().TrimEnd('\r', '\n');

var res =
    OAuthRequest.Create(consumer,accessToken)
    .SetHttpMethod(HttpMethodType.Post)
    .SetUrl("http://api.twitter.com/1/statuses/update.xml")
    .AddParameter(new Parameter(){Key="status",Value=postText})
    .CommitRequest()
    .GetResponse();

Get HomeTimeLine And Mentions

You can reuse Request of construction on the way.
Method operate DeepCopy Instance. so it is thread safety.

//With proxy and if failed with Http Status Code over 500, Retry 3 times
var requestBase =
    OAuthRequest.Create(consumer, accessToken)
    .SetProxy(new WebProxy("http://proxy:8080"))
    .SetRetryCount(3)
    .SetIgnoreStatusCodeCondition(i => i >= 500)
    .AddParameter(new Parameter(){Key="count",Value="100"})
    .SetHttpMethod(HttpMethodType.Get);

//With Proxy and don't Retry
var readyHomeTimeLineRequest =
     requestBase
    .SetRetryCount(0)
    .SetUrl("http://api.twitter.com/1/statuses/home_timeline.xml")
    .CommitRequest();

//With proxy and if failed with Http Status Code over 500, Retry 3 times
var readyMentionTimeLineRequest =
    requestBase
    .SetUrl("http://api.twitter.com/1/statuses/mentions.xml")
    .CommitRequest();
    
    
//Without proxy and don't Retry
var readyMentionTimeLineRequest =
    requestBase
    .SetUrl("http://api.twitter.com/1/statuses/mentions.xml")
    .SetIgnoreStatusCodeCondition(null)
    .CommitRequest();

Get Twitter AccessToken

Consumer consumer = new Consumer(
                twitterConsumerKey,
                twitterConsumerSecret);

//Get Request Token
RequestToken requestToken = OAuthAuthorizationService.GetRequestToken(
    consumer,
    "http://twitter.com/oauth/request_token",
    "http://twitter.com/",
    HttpMethodType.Get).Token as RequestToken;

//It is necessary you have authenticated to user. 
Process.Start(OAuthAuthorizationService.GetUserAuthorizationURL(
    "http://twitter.com/oauth/authorize",
    requestToken));

//You have inputted to user.
Console.Out.WriteLine("Please input verify...");

string verifier = Console.In.ReadLine().TrimEnd('\r', '\n');

//Get AccessToken

AccessToken accessToken =  OAuthAuthorizationService.GetAccessToken(
    consumer,
   "http://twitter.com/oauth/access_token",
    "http://twitter.com/",
    requestToken,
    verifier,
    HttpMethodType.Post).Token as AccessToken;
    
AccessToken accessToken = accessTokenResponse.Token;

Last edited Jul 26, 2010 at 10:41 PM by ugaya40, version 15