C# 如何使用twitter api获取好友活动?
我无法从twitter api获取列表或集合,该api返回我的好友活动C# 如何使用twitter api获取好友活动?,c#,wpf,twitter,C#,Wpf,Twitter,我无法从twitter api获取列表或集合,该api返回我的好友活动 基本上,我想要我朋友的活动列表,就像twitter在其网站上有活动或互动部分一样 您可以使用站点流来实现这一点。首先,获取好友ID列表,然后将其添加到网站流中。下面是一个使用LINQ到Twitter的示例: Console.WriteLine("\nStreamed Content: \n"); int count = 0; (from strm in twitterCtx.
基本上,我想要我朋友的活动列表,就像twitter在其网站上有活动或互动部分一样 您可以使用站点流来实现这一点。首先,获取好友ID列表,然后将其添加到网站流中。下面是一个使用LINQ到Twitter的示例:
Console.WriteLine("\nStreamed Content: \n");
int count = 0;
(from strm in twitterCtx.UserStream
where strm.Type == UserStreamType.Site &&
strm.Follow == "15411837,16761255"
select strm)
.StreamingCallback(strm =>
{
Console.WriteLine(strm.Content + "\n");
if (count++ >= 10)
{
strm.CloseStream();
}
})
.SingleOrDefault();
您可以在中找到更多信息
此外,无论你使用什么技术,你都应该阅读
注意:Twitter站点流处于测试阶段,因此您需要与他们联系以获取访问权限。要能够监视您在Twitter上的朋友,您需要使用UserStream() 虽然它的实现缺少UserStream的一些功能,但是Tweetinvi API能够轻松地检测你的朋友在twitter上做了什么 以下是一个例子:
// Register the Twitter Credentials
IToken token = new Token("userKey", "userSecret", "consumerKey", "consumerSecret");
// Create the stream
IUserStream userStream = new UserStream();
// Register to an event that triggers when a tweet is created by a user you follow
userStream .TweetCreatedByAnyoneButMe += (sender, args) =>
{
Console.WriteLine("Tweet '{0}' created by {1}!", args.Value.Text, args.Value.Creator.Id);
};
// Start the stream
userStream.StartStream(token);
这段代码将在您跟踪的用户每次创建Tweet时调用Console.Writeline()
正如我所说,所有功能尚未实现,但您已经可以收听许多不同的事件,如tweet、消息、follow…以及过滤您收到的tweet(Twitter UserStream默认情况下不可能)
希望这对您有所帮助:)
编辑:你可以在那里找到API->你使用的是哪种语言?嗨@DiogoMoreira--我使用的是wpf C#。谢谢@Joe Mayo--很抱歉没有提到库名,我使用的是TweetSharp库,你能提供使用TweetSharp的相同示例吗?谢谢你宝贵的建议。