[英]How to get the friends activities using twitter api?
我無法從twitter api獲取列表或集合,該列表或集合返回了我的朋友活動。
基本上,我想要我的朋友的活動列表,就像twitter的網站上有“活動或互動”部分一樣。
您可以使用網站流來做到這一點。 首先,獲取您的朋友ID的列表,然后將其添加到網站流中。 這是使用LINQ to 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();
您可以在LINQ to Twitter文檔中找到更多信息。
另外,無論使用哪種技術,都應閱讀Twitter的Site Streams文檔 。
注意:Twitter網站流處於Beta版,因此您需要與它們聯系以進行訪問。
為了能夠在Twitter上監視您的朋友,您需要使用UserStream( https://dev.twitter.com/docs/streaming-apis/streams/user )。
盡管其實現缺少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()!
正如我所說的,所有功能尚未實現,但是您已經可以收聽許多不同的事件,例如Tweets,Messages,Follows ...以及過濾收到的Tweets(默認情況下,Twitter UserStream無法實現)。
希望這個能對您有所幫助 :)
編輯:您可以在此處找到API-> http://tweetinvi.codeplex.com/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.