ahmdrz/goinsta

User.Following() returns no data for private users (includes bug fix)

lucasmendesorg opened this issue · 1 comments

Hi,

User.Sync() (users.go) is using insta.sendSimpleRequest() w/ no request signature, so IG cannot detect it's coming from a allowed Account that's really following the User and can access his profile data. That's the reason why sometimes User.Following() fails. Here's my bug fix suggestion:

In users.go:

func (user *User) Sync(params ...interface{}) error {
	insta := user.inst
	data, err := insta.prepareData()
	if err != nil {
		return err
	}
	body, err := insta.sendRequest(&reqOptions{
		Endpoint: fmt.Sprintf(urlUserInfo, user.ID),
		Query:    generateSignature(data),
		IsPost:   true,
	})
	if err == nil {
		resp := userResp{}
		err = json.Unmarshal(body, &resp)
		if err == nil {
			*user = resp.User
			user.inst = insta
			for _, param := range params {
				switch b := param.(type) {
				case bool:
					if b {
						err = user.FriendShip()
					}
				}
			}
		}
	}
	return err
}

Thank you.

Thank you for your interest. Please create a PR and put your codes there.