goinsta icon indicating copy to clipboard operation
goinsta copied to clipboard

Users.Next() returns false immediately or hangs

Open 0xc0392b opened this issue 5 years ago • 4 comments

Assume something along the lines of:

  user, err := i.Profiles.ByName(uname)
  if err != nil {
    // handle err
  }

  users := user.Following()

  following := make([]goinsta.User, 0)

  for users.Next() {
    if users.Error() != nil {
      // handle err
    } else {
      following = append(following, users.Users...)
    }
  }

users.Next() sometimes returns false immediately or, most of the time, just gets stuck and pegs the CPU at 100%.

Am I doing something wrong or is this part of the library currently broken due to changes made on Instagram's end?

Thanks.

0xc0392b avatar Jan 18 '20 18:01 0xc0392b

Seems related to the problem regarding next_max_id, maybe you could give #306 a try.

buckket avatar Apr 02 '20 12:04 buckket

Tested #306 and getting even weirder behaviour .. users.Next() works once or twice most of the time - users.Users contains a list of 100 users (yay). Sometimes .Next gets stuck, sometimes it returns false and users.Users is empty.

I would like to help you with this but honstly don't know where to begin - this intermittent behaviour is very confusing. Do you think it's to do with rate-limiting?

0xc0392b avatar Apr 03 '20 00:04 0xc0392b

I’ve tested the fix successfully with fairly large profiles, getting more than 1000 Users returned.

You can check for problems if you call Error() in and after your Next() for loop like so:

var users []goinsta.User
followers := profile.Following()
for followers.Next() {
	err = followers.Error(); if err != nil {
		log.Fatal(err)
	}
	users = append(users, followers.Users...)
}
err = followers.Error(); if err != nil {
	log.Fatal(err)
}

buckket avatar Apr 03 '20 22:04 buckket

I've the same problem, here is my error: 2020/12/10 02:09:10 json: cannot unmarshal number into Go struct field Users.next_max_id of type string

sfelaco avatar Dec 10 '20 01:12 sfelaco