Add new comment

small fix for Twitterizer2

Twitterizer is a very good twitter API library for .Net developers. I used this library to build customized twitter application. During this project I came across a little issue with Twitterizer2. In the current version of Twitterizer2 if you want to get user timeline, you need to use TwitterTimeline class and its static methods but, usually when dealing with twitter API it’s always better to use asynchronous methods, considering this, we need to use TwitterTimelineAsync class, and here we face a little issue, because we need to use this method:

public static IAsyncResult UserTimeline(OAuthTokens tokens, UserTimelineOptions options, TimeSpan timeout, Action<TwitterAsyncResponse<TwitterStatusCollection>> function)

The problem here is: in some scenarios we don’t have that user tokens, so, we need other version of this method that doesn’t require the user tokens. and here is my solution:

In the AsyncUtility class add this new Async method:

        public static IAsyncResult ExecuteAsyncMethod<TResponse, TProperties>(TProperties properties, TimeSpan timeout, Func< TProperties, TwitterResponse<TResponse>> methodToCall, Action<TwitterAsyncResponse<TResponse>> function)            where TResponse : ITwitterObject
            where TProperties : OptionalProperties
            return methodToCall.BeginInvoke( properties, result => OneParamNoTokenCallback(result, timeout, methodToCall, function), null);
            ThreadPool.QueueUserWorkItem(result => OneParamNoTokenCallback(methodToCall( properties), timeout, methodToCall, function));
            return null;

In the TwitterTimelineAsync class add new version of  UserTimeline method without tokens parameter like this:

        public static IAsyncResult UserTimeline(UserTimelineOptions options, TimeSpan timeout, Action<TwitterAsyncResponse<TwitterStatusCollection>> function)
            return AsyncUtility.ExecuteAsyncMethod(options, timeout, TwitterTimeline.UserTimeline, function);

Now we are ready to go, and here is a piece of code to explain how to use this new method:

            UserTimelineOptions options = new UserTimelineOptions();
            options.ScreenName = "ali_issam";
                TwitterTimelineAsync.UserTimeline(options, TimeSpan.FromSeconds(60), res =>
                    if (res.Result == RequestResult.Success)
                        //process the tweets here
                    }                });
            catch (Exception ex)

  This is it! I’ve sent this fix to the great team behind this excellent project and I hope they will consider it in the next updates.


Articles Categories: