Twitter From ASP.NET – Direct Messages

tp_vol4_022 As you continue building up your Twitter application, you’ll eventually want some way of retrieving direct messages sent to you.

In a lot of ways this will be very similar to retrieving the messages from your friends, but there is the optional parameters object that we can pass that will allow us to retrieve a subset of the messages.

The code for retrieving and displaying the direct messages sent to you is remarkably similar to the code we wrote earlier that retrieved the messages sent by our friends.  You’ll need to create a class called “Direct” and add a method to it named “Messages” with the following code:

public static TwitterStatusCollection
    Messages()
{
    String password =
        HttpContext.Current
          .Session["Password"].ToString();
    String name = HttpContext.Current
        .User.Identity.Name;
    return (new Twitter(name, password))
        .DirectMessages.DirectMessages();
}

Then you’ll need to bind to it in your display code using a repeater that binds to an ObjectDataSource with the ObjectDataSource configured like this

 

        <asp:ObjectDataSource
            ID="ObjectDataSource1"
            runat="server"
            SelectMethod="Messages"
            TypeName="Directs">
            </asp:ObjectDataSource>

Using the parameters parameter, you can retrieve messages since a specific ID, messages prior to an ID, a specific number of messages, or a specific page (see previous entries about Twitter programming in the list below)  The maximum number of direct messages you can retrieve at any one time is 200.

Related Post

2 Responses to “Twitter From ASP.NET – Direct Messages”

Leave a Reply

Comment Policy:

  • You must verify your comment by responding to the automated email that is sent to your email address. Unverified comments will never show.Leave a good comment that adds to the conversation and I'll leave your link in.
  • Leave me pure spam and I'll delete it.
  • Leave a general comment and I'll remove the link but keep the comment.

Notify me of followup comments via e-mail

Bear