Skip to content
This repository was archived by the owner on Aug 25, 2023. It is now read-only.

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

Open
zaddok opened this issue Jan 15, 2019 · 3 comments

Comments

@zaddok
Copy link

zaddok commented Jan 15, 2019

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
Copy link
Author

zaddok commented Jan 15, 2019

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)

@ahmdrz
Copy link
Owner

ahmdrz commented May 3, 2019

Hi, Do you still has this problem?

@ecommodities-inc
Copy link

ecommodities-inc commented Nov 10, 2020

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
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants