0

I tried the code below but again it wasn't exactly as I wanted. Only 1 pearl flood is coming. There are 90 floods. RT ones should not come and should only come flood by call.

as an example I shared the picture. What do I have to do in this situation.

https://hizliresim.com/bltCKn

  const int MaxSearchEntriesToReturn = 100;
        const int SearchRateLimit = 180;

        string searchTerm = "HANEDANLAR MASASININ YER ALTI EGEMENLİĞİ:RİO TİNTO";

        // oldest id you already have for this search term
        ulong sinceID = 1;

        // used after the first query to track current session
        ulong maxID;

        var combinedSearchResults = new List<Status>();

        List<Status> searchResponse =
            await
            (from search in ctx.Search
             where search.Type == SearchType.Search &&
                   search.Query == searchTerm &&
                   search.Count == MaxSearchEntriesToReturn &&
                   search.SinceID == sinceID &&
                   search.TweetMode == TweetMode.Extended
             select search.Statuses)
            .SingleOrDefaultAsync();

        if (searchResponse != null)
        {
            combinedSearchResults.AddRange(searchResponse);
            ulong previousMaxID = ulong.MaxValue;
            do
            {
                // one less than the newest id you've just queried
                maxID = searchResponse.Min(status => status.StatusID) - 1;

                Debug.Assert(maxID < previousMaxID);
                previousMaxID = maxID;

                searchResponse =
                    await
                    (from search in ctx.Search
                     where search.Type == SearchType.Search &&
                           search.Query == searchTerm &&
                           search.Count == MaxSearchEntriesToReturn &&
                           search.MaxID == maxID &&
                           search.SinceID == sinceID &&
                           search.TweetMode == TweetMode.Extended
                     select search.Statuses)
                    .SingleOrDefaultAsync();

                combinedSearchResults.AddRange(searchResponse);
            } while (searchResponse.Any() && combinedSearchResults.Count < SearchRateLimit);


            combinedSearchResults.ForEach(tweet => 
                Console.WriteLine(
                    "\n  User: {0} ({1})\n  Tweet: {2}",

                    tweet.User.ScreenNameResponse,
                    tweet.User.UserIDResponse,
                    tweet.Text ?? tweet.FullText)
                );
        }
        else
        {
            Console.WriteLine("No entries found.");
        }

        ViewBag.Twet = combinedSearchResults.ToList();
NobodyNada
  • 7,529
  • 6
  • 44
  • 51
  • Can you share some code and explain what exactly is going wrong here? – Andy Piper May 18 '20 at 14:49
  • I shared my code. – Ali Yılmaz May 18 '20 at 15:29
  • Can anyone help me please ?? – Ali Yılmaz May 19 '20 at 12:25
  • I am not a C# expert, but the SingleOrDefaultAsync() method only returns a single entry in Linq, so you're explicitly setting the value of `tweets` to a single Tweet result. You would need to change the code to iterate if you expect a list of Tweets. You should also be aware that Twitter's standard search API only covers 7 days of history, so that may explain why you're not getting Tweets earlier than that. – Andy Piper May 19 '20 at 13:52
  • Yes I know I tried ToListAsync() but didnt work I want to do. My goal this link https://twitter.com/yazparov/status/1260670500562440194. When I search keyword "HANEDANLAR MASASININ YER ALTI EGEMENLİĞİ:"RİO TİNTO"" get all twets 1 to 90. How can I do this. – Ali Yılmaz May 19 '20 at 14:46

1 Answers1

1

I own LINQ to Twitter. A paged search can return more values. Here's an example:

const int MaxSearchEntriesToReturn = 100;
const int SearchRateLimit = 180;

string searchTerm = "Flood Name";

// oldest id you already have for this search term
ulong sinceID = 1;

// used after the first query to track current session
ulong maxID; 

var combinedSearchResults = new List<Status>();

List<Status> searchResponse =
    await
    (from search in twitterCtx.Search
     where search.Type == SearchType.Search &&
           search.Query == searchTerm &&
           search.Count == MaxSearchEntriesToReturn &&
           search.SinceID == sinceID &&
           search.TweetMode == TweetMode.Extended
     select search.Statuses)
    .SingleOrDefaultAsync();

if (searchResponse != null)
{
    combinedSearchResults.AddRange(searchResponse);
    ulong previousMaxID = ulong.MaxValue;
    do
    {
        // one less than the newest id you've just queried
        maxID = searchResponse.Min(status => status.StatusID) - 1;

        Debug.Assert(maxID < previousMaxID);
        previousMaxID = maxID;

        searchResponse =
            await
            (from search in twitterCtx.Search
             where search.Type == SearchType.Search &&
                   search.Query == searchTerm &&
                   search.Count == MaxSearchEntriesToReturn &&
                   search.MaxID == maxID &&
                   search.SinceID == sinceID &&
                   search.TweetMode == TweetMode.Extended
             select search.Statuses)
            .SingleOrDefaultAsync();

        combinedSearchResults.AddRange(searchResponse);
    } while (searchResponse.Any() && combinedSearchResults.Count < SearchRateLimit);

    combinedSearchResults.ForEach(tweet =>
        Console.WriteLine(
            "\n  User: {0} ({1})\n  Tweet: {2}",
            tweet.User.ScreenNameResponse,
            tweet.User.UserIDResponse,
            tweet.Text ?? tweet.FullText)); 
}
else
{
    Console.WriteLine("No entries found.");
}

There are a few things to pay attention to:

  • Set Count to MaxSearchEntriesToReturn because it defaults to 15 and you want to minimize the number of queries.
  • The while loop checks SearchRateLimit because there are rate limits that will cause you to get an HTTP 429. The rate limit for App-Only is higher than the 180 I've added here.
  • Notice how I'm using SinceID and MaxID to page through results. See Working with Timelines in the Twitter API docs to understand what those are.
  • Also, please read the Search API docs and notice that the standard search API is focused on relevance and not completeness.
Joe Mayo
  • 7,501
  • 7
  • 41
  • 60
  • Hi, How can I make tweets before 7 days. There is registration on this site. How this site does it. Do you know below website. https://threadreaderapp.com/search?q=HANEDANLAR+MASASININ+YER+ALTI+EGEMENL%C4%B0%C4%9E%C4%B0%3AR%C4%B0O+T%C4%B0NTO – Ali Yılmaz May 25 '20 at 13:55