Search fails with maxid (ulong.max) and thenid, but separately it works
the following query works fine if you comment out either the "ID" or "MaxID" clause, but when both are included, a "bad url" exception is thrown.
var maxId = ulong.MaxValue;
var sinceId = (ulong)341350918903701507;
var searchResult =
(
from search in ctx.Search
where search.Type == SearchType.Search &&
search.ResultType == ResultType.Mixed &&
search.Query == "red wedding" &&
search.SinceID == sinceId &&
search.MaxID == maxId &&
search.IncludeEntities == false &&
search.Count == 200
select search).SingleOrDefault();
source to share
If you look at the result of the request in Fiddler, you can see that the response is:
{"errors":[{"code":195,"message":"Missing or invalid url parameter"}]}
I can't answer the question why Twitter won't accept requests with both IDID and MaxID. However, the request is well formed and there is no documentation describing the restrictions on the relationship between the two for this particular scenario. The purpose of the MaxID is to be the ID of the highest tweet in order to return to the next request. Both MaxID and IDID are meant to help you browse. I wrote a blog post on how to do this:
source to share
I seem to have the same problem as yours, so the only solution I had was to do it manually, so first I got the first list giving the fromId value to what I have:
var searchResult =
(
from search in TwitterCtx.Search
where search.Type == SearchType.Search &&
search.Query == query &&
search.Count == pageSize &&
search.IncludeEntities == true &&
search.ResultType == ResultType.Recent &&
search.SinceID == sinceId
select search
).SingleOrDefault<Search>();
resultList = searchResult.Statuses;
Then I need to look for other tweets (the case where the number of new tweets is larger is the page size), so I had a while loop like this:
ulong minId = ulong.Parse(resultList.Last<Status>().StatusID) - 1;
List<Status> newList = new List<Status>();
while (minId > sinceId)
{
resultList.AddRange(newList);
searchResult =
(
from search in TwitterCtx.Search
where search.Type == SearchType.Search &&
search.Query == query &&
search.Count == pageSize &&
search.IncludeEntities == true &&
search.ResultType == ResultType.Recent &&
search.MaxID == minId &&
search.SinceID == sinceId
select search
).SingleOrDefault<Search>();
newList = searchResult.Statuses;
if (newList.Count == 0)
break;
minId = ulong.Parse(newList.Last<Status>().StatusID) - 1;
}
Now for some reason, you can use both fromId and maxId here.
source to share
I used to get the same "Missing or Invalid URL Parameter" error, but according to Joe Mayo's solution , I added an extra if (fromID <maxID) before the while loop because the request throws the error above whenever maxID is less than cID. I think this is wrong.
if (sinceID < maxID)
{
do
{
// now add sinceID and maxID
searchResponse =
await
(from search in twitterCtx.Search
where search.Type == SearchType.Search &&
search.Query == "from:@" + twitterAccountToDisplay + " -retweets" &&
search.Count == count &&
search.SinceID == sinceID &&
search.MaxID == maxID
select search)
.SingleOrDefaultAsync();
if (searchResponse == null)
break;
if (searchResponse.Count > 0 && searchResponse.Statuses.Count > 0)
{
newStatuses = searchResponse.Statuses;
// first tweet processed on current query
maxID = newStatuses.Min(status => status.StatusID) - 1;
statusList.AddRange(newStatuses);
lastStatusCount = newStatuses.Count;
}
if (searchResponse.Count > 0 && searchResponse.Statuses.Count == 0)
{
lastStatusCount = 0;
}
}
while (lastStatusCount != 0 && statusList.Count < maxStatuses);
//(searchResponse.Count != 0 && statusList.Count < 30);
}
source to share