goinsta
goinsta copied to clipboard
Using .Followers() or .Following() fails when examining user returned by a search.
The following code fails with a nil pointer exception:
searchResult, err := ig.Search.User(searchUsername)
if err != nil {
return err
}
if len(searchResult.Users) == 0 {
return errors.New("Specified user is not found by instagram search: " + searchUsername)
}
followers := searchResult.Users[0].Following()
if followers == nil {
return errors.New("users.Following() returned nil object")
}
err := followers.Error()
if err != nil {
fmt.Println("####", err) // This never prints
}
for followers.Next() {
for _, u := range followers.Users {
// Do something
// ...
}
}
It fails with the following:
panic(0x153cbe0, 0x1a55e40)
/usr/local/go/src/runtime/panic.go:513 +0x1b9
github.com/zaddok/goinsta/v4.(*Users).Next(0xc0001341c0, 0xc0001341c0)
/Users/sample/go/pkg/mod/github.com/ahmdrz/goinsta/[email protected]/users.go:61 +0x184
main.GetFollowing(0xc0000a00d0, 0xc00040e000, 0x2, 0x1f, 0x0, 0x0, 0x20)
/Users/sample/go/ig/ig.go:270 +0x131
I suspect this code:
func (user *User) Following() *Users {
users := &Users{}
users.inst = user.inst
users.endpoint = fmt.Sprintf(urlFollowing, user.ID)
return users
}
It appears to assume user.inst
has a value, when it may not always have (i.e. if doing a search for users)
Hi, Do you still has this problem?
It looks like the request to instagram was removed possibly because of the API changes. The URL in const.go doesn't work also.
func (user *User) Followers() *Users {
users := &Users{}
users.inst = user.inst
users.endpoint = fmt.Sprintf(urlFollowers, user.ID)
return users
}