1

I am creating a small program to get a instagram users following list using C# and instasharp. The code below will get me the first 50. I believe I have to use the pagination option to get the next url to get to the next page. Thats where Im stuck. How do I use pagination to loop through all of a users following?

var config = new InstaSharp.InstagramConfig("api", "oauth", "xxxxxx", "xxxxxxx", "xxxxxx");

var config1 = new InstaSharp.Endpoints.Relationships.Unauthenticated(config);
var result = config1.Follows(000000);

dynamic dyn = JsonConvert.DeserializeObject(result.Json);
foreach (var data in dyn.data)
{
    listBox1.Items.Add(data.username);
}
stderr
  • 8,567
  • 1
  • 34
  • 50
Tony
  • 11
  • 1
  • 2
  • Might be a duplicate of http://stackoverflow.com/questions/19630605/how-do-i-access-pagination-in-usersresponse-from-the-relationships-endpoint-in-i – TaRDy Aug 05 '14 at 12:01
  • No Ive seen that and it gives some suggestions but no real answer or example. Thanks. – Tony Aug 05 '14 at 12:26
  • The point is that you shouldn't be asking a question if it has already been asked, regardless of the quality of the responses in the other question. – TaRDy Aug 05 '14 at 12:37
  • I am unfamiliar with this library, but if you look at the Relationships unit tests on the github (/src/InstaSharp.Tests/Relationships.cs) you will see an example of how to use pagination, see my answer here http://stackoverflow.com/a/25139236/88217 – TaRDy Aug 05 '14 at 12:50
  • Whats is /*ffujiy*/? How would your example be implemented into mine to loop through and get all the users? Where does pagination come into play, at what point? That question has to do with there not being any pagination at that time, Im not going to add something to an old outdated question. – Tony Aug 05 '14 at 13:18
  • /* ffujiy */ is a comment, most likely the username for the ID used in the test case. – TaRDy Aug 05 '14 at 17:03

1 Answers1

2

Based on my response here: https://stackoverflow.com/a/25139236/88217

If you look at the unit tests on the InstaSharp github, you can see an example of how to use Pagination:

    public async Task Follows_NextCursor()
    {
        //This test will fail if testing with an account with less than one page of follows
        var result = await relationships.Follows();
        result = await relationships.Follows(457273003/*ffujiy*/, result.Pagination.NextCursor);
        Assert.IsTrue(result.Data.Count > 0);
    }

In the case where you want to loop through and get all of them, I would expect you to do something like this:

int userID = 000000;
var result = await relationships.Follows(userID);

while(result.Data.Count > 0)
{
  dynamic dyn = JsonConvert.DeserializeObject(result.Json);
  foreach (var data in dyn.data)
  {
    listBox1.Items.Add(data.username); 
  }

  result = await relationships.Follows(userID, result.Pagination.NextCursor)
}

Because this code uses await, you will have to mark the method as async, for more information on what that entails, I would suggest looking at the async/await keywords, a good introduction can be found at Stephen Cleary's Blog

Community
  • 1
  • 1
TaRDy
  • 999
  • 1
  • 8
  • 21