views:

391

answers:

3

Hey all,

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

A: 

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

James
Hi, I don't mind skipping the API for this bit and simply creating my POST header. What method should I try and call using my custom header?Thanks for the help
SSL
A: 

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

Justin
Hi, I don't quite understand how an UpdatePanel is used to update Twitter's page?
SSL
I think I misunderstood what you were doing. Are you using a desktop application to submit to Twitter but not to read from it? You're not using the Twitter API to display information on an ASP.NET page you've written? If you're expecting to refresh a browser window that is separate from your desktop app from inside your desktop app you're going to need some API into the browser not into Twitter.
Justin
Hi, I'm creating a desktop app and an ASP.NET page. I don't mind if this doesn't work for the desktop app. I don't want to update my page, I want to update the Twitter page itself. Like when you get a new tweet, it automatically shows the new tweet without refreshing the page. I'm wondering if there's an AJAX call I can make to have my application do that. (e.g. when I update the profile picture, it should change without a refresh on the actual Twitter page) thanks
SSL
Are you talking about you want to update your twitter.com page? If so, I do not think you can since twitter.com is not controlled by you. But you can create your own page to consume the twitter api (that is why twitter.com publishes it is API so third-party developer can create applications to use twitter service.) by sending ajax request and handle the response on your page in callback function so your created page will not refresh. Do you get what I mean?
schrodinger's code
Hi, I know what you mean and I know it's possible to use AJAX on a site I control. I was hoping that maybe the Twitter API has a method that allows others to access their Update method. For example, when you tweet, it partially updates and the tweet appears without the entire page refreshing. I was hoping this might be possible with aspects other than just tweets
SSL
+1  A: 

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();
amelvin
Hi, Thanks for the help. I can't try the code atm, but would your code change the Twitter page itself? That's what I'm aiming to do. So, if a user updates something in my application, they can then see the Twitter.com page update automatically via a partial postback
SSL
@superexsl I've added an example on posting an update to Twitter using Tweetsharp
amelvin