如何使用 TweetSharp 访问推文历史对话?
我正在尝试使用 TweetSharp 访问推文对话历史记录。
要求是,如果我使用一条推文项目的 id,它应该 返回该推文之前的整个线程。
但找不到通过 TwittertService 公开的此类方法,其中 我可以传递当前的 Tweet _id 并获取对话详细信息。
我按照以下方法获取集合(列表),即,
List<TwitterStatus> list = new List<TwitterStatus>();
private void GetReplied(TwitterStatus twitter, TwitterResponse twitterResponse)
{
if (twitter.InReplyToStatusId != null)
{
long statusID = (long)twitter.InReplyToStatusId;
this.ts.GetTweet(statusID, (twitterRecursive,
twitterResponseRecursive) =>
{
list.Add(twitterRecursive);
if (twitter.InReplyToStatusId != null)
{
this.GetReplied(twitterRecursive,
twitterResponseRecursive);
}
});
}
else
{
Debug.WriteLine(list.Count);
foreach (TwitterStatus status in list)
{
Debug.WriteLine(status.Text);
}
}
}
this.ts.GetTweet(<tweet Id>, twitterResponse) =>
{
list.Add(twitter);
this.GetReplied(twitter, twitterResponse);
});
只是想听听您的建议。我们有这样的方法吗 可以使用 TweetSharp 或任何替代方法来实现吗?
非常感谢您的帮助。
I am trying to access a tweet conversation history using TweetSharp.
The requirement is like, if I use id of one tweet item it should
return me the whole thread that followed before that tweet item.
But could not find such method exposed through TwittertService, where
I can pass the current Tweet _id and get the conversation details.
I followed the following approach to get the collection (list) ie,
List<TwitterStatus> list = new List<TwitterStatus>();
private void GetReplied(TwitterStatus twitter, TwitterResponse twitterResponse)
{
if (twitter.InReplyToStatusId != null)
{
long statusID = (long)twitter.InReplyToStatusId;
this.ts.GetTweet(statusID, (twitterRecursive,
twitterResponseRecursive) =>
{
list.Add(twitterRecursive);
if (twitter.InReplyToStatusId != null)
{
this.GetReplied(twitterRecursive,
twitterResponseRecursive);
}
});
}
else
{
Debug.WriteLine(list.Count);
foreach (TwitterStatus status in list)
{
Debug.WriteLine(status.Text);
}
}
}
this.ts.GetTweet(<tweet Id>, twitterResponse) =>
{
list.Add(twitter);
this.GetReplied(twitter, twitterResponse);
});
Just wanted to have your advice, on that. Do we have any such method
with TweetSharp or any alternative approach can be implemented?
Really appreciate your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您必须这样做:从一条推文开始,然后遍历其
in_reply_to_status_id
链。我做的一件事(尽管可能不适用于您)是在从 Twitter 获取推文之前检查本地推文缓存,看看我是否已经获取了正在回复的推文。
至于让这变得更容易的库,我不知道有什么。无论他们是否公开更简化的方法,在幕后他们仍然必须执行您在代码中实现的过程。
要了解另一个库如何完成此任务,请查看此 Twitterizer 示例 。
Yep, that's how you'll have to do it: start with a tweet and walk its
in_reply_to_status_id
chain.One thing I do, although it may not be applicable to you, is check a local cache of tweets before fetching from Twitter to see if I already fetched the tweet being replied to.
As for libraries that make this easier, I don't know of any. Regardless of whether they expose a more streamlined method, under the covers they'll still have to perform the process that you implemented in your code.
To see how another library approached this task, take a look at this Twitterizer sample.