goinsta icon indicating copy to clipboard operation
goinsta copied to clipboard

Using .Followers() or .Following() fails when examining user returned by a search.

Open zaddok opened this issue 5 years ago • 3 comments

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

zaddok avatar Jan 15 '19 11:01 zaddok

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)

zaddok avatar Jan 15 '19 11:01 zaddok

Hi, Do you still has this problem?

ahmdrz avatar May 03 '19 14:05 ahmdrz

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
}

ecommodities-inc avatar Nov 10 '20 12:11 ecommodities-inc