Can`t figure out pagination Api Search Result

Dec 24, 2014 at 1:34 AM
Hello, I can`t figure out how to set a cursor or pagination for the search api. I would like for each press of button to get another 100 results, how can I do this?:
private void button9_Click(object sender, EventArgs e)
        {
.....................................................................
            var searchResponse =
                await
                (from search in twitterCtx.Search
                 where search.Type == SearchType.Search &&
                       search.Query == q &&
                       search.Count == 100 &&
                       search.SearchLanguage == lang &&
                       search.ResultType == ResultType.Recent
                       
                 select search)
                .SingleOrDefaultAsync();
Dec 30, 2014 at 4:12 PM
Any help please on how to get the next and next results?
Coordinator
Dec 30, 2014 at 7:16 PM
Hi,

I wrote a blog post that explains how to use SinceID and MaxID to page through results:

Working with Timelines with LINQ to Twitter

This is for an older version of LINQ to Twitter, but the concepts are the same.

@JoeMayo
Dec 31, 2014 at 1:22 PM
Edited Dec 31, 2014 at 7:28 PM
I little figure it out ...
            var userStatusResponse =
                (from search in twitterCtx.Search
                 where search.Type == SearchType.Search &&
                       search.Query == q &&
                       search.Count == Count &&
                       search.SinceID == sinceID &&
                       search.SearchLanguage == lang &&
                       search.ResultType == ResultType.Recent
                 select search)
                .ToList();


            // first tweet processed on current query
            maxID = userStatusResponse.Min(
                search => search.MaxID) - 1;

            do
            {
                // now add sinceID and maxID
                userStatusResponse =
                    (from search in twitterCtx.Search
                     where search.Type == SearchType.Search &&
                           search.Query == q &&
                           search.Count == Count &&
                           search.SinceID == sinceID &&
                           search.MaxID == maxID &&
                           search.SearchLanguage == lang &&
                           search.ResultType == ResultType.Recent
                     select search)
                    .ToList();

                if (userStatusResponse.Count > 0)
                {
                    // first tweet processed on current query
                    maxID = userStatusResponse.Min(
                        search => search.MaxID) - 1;

                    statusList.AddRange(userStatusResponse);
                }
            }
            while (userStatusResponse.Count != 0 && statusList.Count < 30);


            for (int i = 0; i < statusList.Count; i++)
            {
                Search search = statusList[i];

                Search search = statusList[i];
                search.Statuses.ForEach(tweet =>
                {
                    if (tweet.User.DefaultProfileImage)
                    {
                        avatarprof = "NO";

                    }
                    else
                    {
                        avatarprof = "YES";
                    }

                    //dataGridView2.Rows.Add(new object[] { tweet.User.ScreenNameResponse, tweet.Text });
                    string[] row = { tweet.User.ScreenNameResponse, tweet.Text, avatarprof, tweet.StatusID.ToString() };
                    var listViewItem = new ListViewItem(row);
                    listView1.Items.Add(listViewItem);
                    //MessageBox.Show(tweet.Text);
                    //richTextBox3.AppendText("User: " + tweet.User.ScreenNameResponse + " --- Tweet: " + tweet.Text + "\n");
                });
            }
Dec 31, 2014 at 7:10 PM
Edited Jan 1, 2015 at 9:58 AM
How can I get the current tweet ID? Cuz I use maxID now ...


// first tweet processed on current query
        maxID = userStatusResponse.Min(search => search.MaxID) - 1;
Jan 2, 2015 at 12:51 PM
Edited Jan 2, 2015 at 1:43 PM
I think I got it but the do - while stuck my app, is this the correct version?
            ulong sinceID = 1;
            ulong maxID;
            ulong currentID = 0;
            var statusList = new List<Search>();
           var auth = apiConnect();
            var twitterCtx = new TwitterContext(auth);

            // last tweet processed on previous query set
            const int Count = 10;
            List<ulong> list1 = new List<ulong>();
            List<ulong> list2 = new List<ulong>();

            var searchResponse =
                (from search in twitterCtx.Search
                 where search.Type == SearchType.Search &&
                       search.Query == q &&
                       search.Count == Count &&
                       search.SinceID == sinceID &&
                       search.SearchLanguage == lang &&
                       search.ResultType == ResultType.Recent
                 select search)
                .ToList();

            // first tweet processed on current query

            foreach (Search c in searchResponse)
            {

                foreach (Status v in c.Statuses)
                {
                    list1.Add(v.StatusID);
                }
            }

            ulong[] terms1 = list1.ToArray();

            maxID = terms1.Min() - 1;

            do
            {
                // now add sinceID and maxID
                searchResponse =
                    (from search in twitterCtx.Search
                     where search.Type == SearchType.Search &&
                           search.Query == q &&
                           search.Count == Count &&
                           search.SinceID == sinceID &&
                           search.MaxID == maxID &&
                           search.SearchLanguage == lang &&
                           search.ResultType == ResultType.Recent
                     select search)
                    .ToList();

                if (searchResponse.Count > 0)
                {
                    // first tweet processed on current query
                    foreach (Search c in searchResponse)
                    {

                        foreach (Status v in c.Statuses)
                        {
                            list2.Add(v.StatusID);

                        }
                    }

                    ulong[] terms2 = list2.ToArray();
                    maxID = terms2.Min() - 1;
                    label18.Text = terms2.Min().ToString();

                    statusList.AddRange(searchResponse);
                }
            } while (searchResponse.Count != 0 && statusList.Count < 30);

            for (int i = 0; i < statusList.Count; i++)
            {
                Search search = statusList[i];
                search.Statuses.ForEach(tweet =>
                {
                    if (tweet.User.DefaultProfileImage)
                    {
                        avatarprof = "NO";

                    }
                    else
                    {
                        avatarprof = "YES";
                    }

                    string[] row = { tweet.User.ScreenNameResponse, tweet.Text, avatarprof, tweet.StatusID.ToString() };
                    var listViewItem = new ListViewItem(row);
                    listView1.Items.Add(listViewItem);

                });
            }