LinqToTwitter.收藏夹-获取全部
本文关键字:全部 获取 收藏夹 LinqToTwitter | 更新日期: 2023-09-27 18:20:23
我已经编写了获取一组用户收藏夹的代码,然而,不明显的是,我如何通过这些页面/光标来获取,比如说,用户的第一组收藏夹。光标值始终为0,max/since ID
为空。有没有一种方法可以使用LinqToTwitter实现这一点?
对于收藏夹,您需要使用SinceID/MaxID遍历时间线。这里有一个例子:
static async Task ShowFavoritesAsync(TwitterContext twitterCtx)
{
const int PerQueryFavCount = 200;
// set from a value that you previously saved
ulong sinceID = 1;
var favsResponse =
await
(from fav in twitterCtx.Favorites
where fav.Type == FavoritesType.Favorites &&
fav.Count == PerQueryFavCount
select fav)
.ToListAsync();
if (favsResponse == null)
{
Console.WriteLine("No favorites returned from Twitter.");
return;
}
var favList = new List<Favorites>(favsResponse);
// first tweet processed on current query
ulong maxID = favList.Min(fav => fav.StatusID) - 1;
do
{
favsResponse =
await
(from fav in twitterCtx.Favorites
where fav.Type == FavoritesType.Favorites &&
fav.Count == PerQueryFavCount &&
fav.SinceID == sinceID &&
fav.MaxID == maxID
select fav)
.ToListAsync();
if (favsResponse == null || favsResponse.Count == 0) break;
// reset first tweet to avoid re-querying the
// same list you just received
maxID = favsResponse.Min(fav => fav.StatusID) - 1;
favList.AddRange(favsResponse);
} while (favsResponse.Count > 0);
favList.ForEach(fav =>
{
if (fav != null && fav.User != null)
Console.WriteLine(
"Name: {0}, Tweet: {1}",
fav.User.ScreenNameResponse, fav.Text);
});
// save this in your db for this user so you can set
// sinceID accurately the next time you do a query
// and avoid querying the same tweets again.
ulong newSinceID = favList.Max(fav => fav.SinceID);
}
我写了一篇博客文章,解释了如何使用Twitter Timelines。它是为LINQ to Twitter的早期非异步版本编写的,但概念保持不变:
使用LINQ到Twitter 处理时间表
这是基于推特的指导,这是一个很好的阅读:
Twitter使用Timelines文档