Skip to content

03. Profiles & Users

David Brouwer edited this page Jan 24, 2022 · 2 revisions

In goinsta, there are two structs related to user accounts, aka profiles. The first is the Profile struct, a convenient all-encompassing instance containing all profile-related content. The second is the User struct, representing only the account information, and used throughout all of goinsta whenever a user is referenced.

Profiles

The Profile struct represents the complete collection of information a user account might have. This includes account info, feed posts, stories, highlights, and IGTV posts. Its primary purpose is to provide a convenient single access point for all info and media related to an account. It is important to distinguish the Profile and Profiles struct, however. The former is everything previously described, and the latter is one of the main goinsta instances exposing methods to fetch a user by either ID or name, although these should be used sparingly, it is better to use the Searchbar methods to find a user. The Profile struct is primarily used in combination with the search functionalities, as a search query for a user will usually return a Profile instance.

The single primary entry point to a user's profile, is the visit profile method. This will simulate a search query, if a profile was found matching the argument the click on the search result will be registered, and page information and the first few media items will be fetched (posts, stories, highlights, igtv).

acc := "joeel56"
profile, err := insta.VisitProfile(acc)
if err != nil {
    log.Fatal(err)
}

user := profile.User
fmt.Printf(
    "%s has %d followers, %d posts, and %d IGTV vids\n", 
    acc, user.FollowerCount, user.MediaCount, user.IGTVCount,
)

status := profile.Friendship
if status.FollowedBy {
    fmt.Printf("%s is following you ;)\n", user.FullName)
} else {
    fmt.Printf("Yikes, not followed by %s\n", user.FullName)
}

feed := profile.Feed
fmt.Printtf("%d posts fetched, more available = %v\n", len(feed.Items), feed.MoreAvailable)

stories := profile.Stories
fmt.Printf("%s currently has %d story posts\n", acc, stories.Reel.MediaCount)

highlights := profile.Highlights
fmt.Printf("%s currently has %d highlights\n", len(highlights))

igtv := profile.IGTV
if len(igtv.Items) > 0 {
    fmt.Printf("First IGTV post title is '%s'\n", igtv.Items[0].Title, igtv.Items[0].ViewCount)
}

The Profiles struct has three main methods

// Directly fetch the User info related to an account name
// Try to avoid this method, and only use it sparingly for testing purposes
user, err := insta.Profiles.ByName("f1")

// Directly fetch the User info related to an account by user ID
// This methods should never really be used, but it is provided 
//   for the off-chance that you do only have an account ID
user, err := insta.Profiles.ByID("12345")

// This will return a list of users that have been blocked by the currently logged in user
blocked, err := insta.Profiles.Blocked()

User

The User struct represents the account information belonging to a user. Basically everything about a user, except post media. The user struct is the general reference to any type of user in goinsta. E.g. posts, tags, comments, likes, all reference to a user, that performed the action, and they will always reference to a User struct instance. This is convenient, because the user struct implements various common methods. If you for example find a comment on a post, but want to visit the user profile that posted that comment, you can simply call comment.User.VisitProfile(), and in this way you can endlessly navigate from one user to another if needed.

A list of all User methods:

// Same as insta.VisitProfile(), except it won't perform a search query, and directly visit the profile 
func (user *User) VisitProfile() (*Profile, error)

// To directly fetch post media, the methods below can be used. 
// It is better however to use the VisitProfile() method and 
//   subsequently further paginate if required.
func (user *User) Feed(params ...interface{}) *FeedMedia
func (user *User) Stories() (*StoryMedia, error)
func (user *User) Highlights() ([]Reel, error)
func (user *User) IGTV() (*IGTVChannel, error)
func (user *User) IGTVSeries() ([]*IGTVChannel, error)

func (user *User) Follow() error
func (user *User) Unfollow() error
func (user *User) Followers() *Users
func (user *User) Following() *Users
func (user *User) ApprovePending() error
func (user *User) IgnorePending() error
func (user *User) GetFeaturedAccounts() ([]*User, error)
func (user *User) GetFriendship() (fr *Friendship, err error)
func (user *User) Info(params ...interface{}) error
func (user *User) SetInstagram(insta *Instagram)
func (user *User) Sync(params ...interface{}) error
func (user *User) Tags(minTimestamp []byte) (*FeedMedia, error)
func (user *User) DownloadProfilePic() ([]byte, error)
func (user *User) DownloadProfilePicTo(dst string) error

// Autoblock = true will automatically also block other accounts 
//   created with the same email/phonenumber
func (user *User) Block(autoBlock bool) error
func (user *User) Unblock() error
func (user *User) Mute(opt muteOption) error
func (user *User) Unmute(opt muteOption) error
Clone this wiki locally