如何使用TweetSharp ListDirectMessageReceived()方法获取新消息的通知?

时间:2013-08-05 14:53:51

标签: wpf twitter tweetsharp

我正在使用TweetSharp为twitter制作一个小型演示桌面应用程序,我使用以下代码获取登录用户的所有消息: -

TwitterService service = new TwitterService("ConsumerKey", "ConsumerSecretKey");
// Step 1 - Retrieve an OAuth Request Token
OAuthRequestToken requestToken = service.GetRequestToken();

// Step 2 - Redirect to the OAuth Authorization URL
Uri uri = service.GetAuthorizationUri(requestToken);
Process.Start(uri.ToString());

// Step 3 - Exchange the Request Token for an Access Token
Console.Write("Enter Pin:: ");
string verifier = Console.ReadLine(); // <-- This is input into your application by your user

OAuthAccessToken access = service.GetAccessToken(requestToken, verifier);

// Step 4 - User authenticates using the Access Token
service.AuthenticateWith(access.Token, access.TokenSecret);

string message = null;

List<string> messages = new List<string>();

IEnumerable<TwitterDirectMessage> directMessages = service.ListDirectMessagesReceived(new ListDirectMessagesReceivedOptions());

//Fetch all current direct message:
foreach (TwitterDirectMessage directMessage in directMessages)
{
    //Write All Messages in Console
    Console.WriteLine(directMessage.Text);
}

上面的foreach循环将显示所有消息但我的问题是,当任何其他用户向我发送新消息时,如何通知我新消息。

请帮助我!

感谢任何帮助!

感谢名单!

1 个答案:

答案 0 :(得分:2)

This TweetSharp code定义了库方法。