Question

I'm using the Twitter API (via TweetSharp) and was wondering if it's possible to automatically refresh the page from the API so that all users see the update? If so, is it also possible to take it one step further by only have a partial page update so only the relevant change is updated instead of the entire page?

Thanks for any help

Was it helpful?

Solution

I think I understand your question, that you want to display a bunch of users and their last tweet - but keep checking if their last tweet has changed and update the screen when the user posts a tweet?

If so the answer is that you need to call the twitterapi asynchronously every so often and pull down the last status (tweet) for each user - and if it is a new one then use ajax to update the part of the screen with the old status (tweet) in it.

In TweetSharp if you have a List of friends, you can pull in their last tweet with something like:

    string profileImageUrl = String.Empty;
    string name = String.Empty;
    string statusText = String.Empty;
    string createdAt = String.Empty;
    string screenName = String.Empty;

    foreach (TwitterUser friend in friends)
    {
        try
        {
            profileImageUrl = String.IsNullOrEmpty(friend.ProfileImageUrl) ? "" : friend.ProfileImageUrl;
            name = String.IsNullOrEmpty(friend.Name) ? "" : friend.Name;
            statusText = (friend.Status == null || friend.Status.Text.Length == 0) ? "unknown" : friend.Status.Text; //stops nullreferenceexception on instance
            createdAt = String.IsNullOrEmpty(friend.CreatedDate.ToString()) ? "" : friend.CreatedDate.ToString();
            screenName = String.IsNullOrEmpty(friend.ScreenName) ? "" : friend.ScreenName;
        }
        catch (NullReferenceException)
        {
            profileImageUrl = "";
            name = "unknown";
            statusText = "unknown";
            createdAt = "";
            screenName = "unknown";

So you can display it on the screen initially.

Then use jquery (or javascript) to periodically hit a web service that reads the twitter api and then use the data returned to update the last tweet if it has changed.

Let me know if I have the wrong end of the stick.

EDIT:

An example of using Tweetsharp posting a new tweet to Twitter is:

var query = FluentTwitter.CreateRequest().AuthenticateAs(username,password).Statuses().Update("Posting status on StackOverflow").AsJson();

OTHER TIPS

I dont use this dll, but I am writing one, and the Twitter API expects you to call again - there is no refresh as I know. If this dll allows you to query since a date then that is possilbe and would probably be a parameter to the call. I hope this helps a little

If you're using ASP .NET you could consider using AJAX with the UpdatePanel control. It would probably be the easiest way to get what you need with ASP .NET

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top