-
Notifications
You must be signed in to change notification settings - Fork 8
Profile
Rahil edited this page Apr 14, 2026
·
3 revisions
-
usernameβ handle name -
pkβ numeric ID -
fullName/name biographyprofilePicURL-
isPrivate,isVerified,isBusinessAccount -
posts,followers,followings(counts)
β οΈ Many methods throw InstagramException (and sometimes IOException). Always handle errors.
var profile = insta.getProfile("target_username");
System.out.println(profile.username + " (" + profile.pk + ") β " + profile.biography);profile.follow(); // follow user
profile.unfollow(); // unfollow uservar postsPaginator = profile.getPosts();
while (postsPaginator.hasNext()) {
var page = postsPaginator.next();
page.forEach(post -> System.out.println(post.id + " β " + post.caption));
}// Followers
var followersPaginator = profile.getFollowers();
while (followersPaginator.hasNext()) {
var page = followersPaginator.next();
page.forEach(p -> System.out.println(p.username + " β " + p.profilePicURL));
}
// Followings
var followingsPaginator = profile.getFollowings();
if (followingsPaginator.hasNext()) {
var firstPage = followingsPaginator.next();
// ...
}var stories = profile.getStory();
stories.forEach(s -> System.out.println("story id: " + s.id + " url: " + s.getUrl()));
var highlights = profile.getHighlights();
highlights.forEach(h -> System.out.println("highlight id: " + h.id));var profile = insta.getProfile("target_username");
profile.follow();
var postsPaginator = profile.getPosts();
if (postsPaginator.hasNext()) {
var firstPage = postsPaginator.next();
firstPage.forEach(p -> System.out.println(p.id + " β " + p.caption));
}- Paginators (
PostPaginator,ProfilePaginator) behave like iterators:-
hasNext()β more pages available -
next()β fetch next page
-
-
getStory()andgetHighlights()return lists (may be empty). - Use
profile.pkfor endpoint-specific requests. - Preserve your
AUTH_TOKENto avoid logging in repeatedly.