问题
I wish to return ALL the Tweets I have ever posted on my timeline.
I am using the Linq To Twitter library as so -
var statusTweets =
from tweet in twitterCtx.Status
where tweet.Type == StatusType.User
&& tweet.UserID == MyUserID
&& tweet.Count == 200
select tweet;
statusTweets.ToList().ForEach(
tweet => Console.WriteLine(
"Name: {0}, Tweet: {1}\n",
tweet.User.Name, tweet.Text));
This works fine and brings back the first 200. However the first 200 seems to be the maximum I can retrieve, as there a way to bring back say 1000? There does not seem to be a next cursor movement
option like there is in other parts of this library to move onto next pages etc.
回答1:
You would use a combination of Count, MaxID, and SinceID to page through tweets. This sounds strange, but there's a very good reason for this approach, given that the tweet stream is continually updating. I've written a blog post, Working with Timelines with LINQ to Twitter, that points to the Twitter documentation and describes how LINQ to Twitter does this.
// last tweet processed on previous query set
ulong sinceID = 210024053698867204;
ulong maxID;
const int Count = 10;
var statusList = new List<status>();
var userStatusResponse =
(from tweet in twitterCtx.Status
where tweet.Type == StatusType.User &&
tweet.ScreenName == "JoeMayo" &&
tweet.SinceID == sinceID &&
tweet.Count == Count
select tweet)
.ToList();
statusList.AddRange(userStatusResponse);
// first tweet processed on current query
maxID = userStatusResponse.Min(
status => ulong.Parse(status.StatusID)) - 1;
do
{
// now add sinceID and maxID
userStatusResponse =
(from tweet in twitterCtx.Status
where tweet.Type == StatusType.User &&
tweet.ScreenName == "JoeMayo" &&
tweet.Count == Count &&
tweet.SinceID == sinceID &&
tweet.MaxID == maxID
select tweet)
.ToList();
if (userStatusResponse.Count > 0)
{
// first tweet processed on current query
maxID = userStatusResponse.Min(
status => ulong.Parse(status.StatusID)) - 1;
statusList.AddRange(userStatusResponse);
}
}
while (userStatusResponse.Count != 0 && statusList.Count < 30);
来源:https://stackoverflow.com/questions/18639108/return-all-tweets-from-my-timeline