32
32
public class Profile {
33
33
protected final AuthInfo authInfo ;
34
34
public String posts_end_cursor ;
35
+ private String nextPageCursor ;
35
36
public String username ;
36
37
public long pk ;
37
38
public String full_name ;
@@ -146,17 +147,17 @@ public static List<Post> _getPosts(@Nullable AuthInfo authInfo,long pk,@Nullable
146
147
}
147
148
148
149
/**
149
- * Get the followers of the user
150
+ * Get the followers of the user. The method is auto paginated
150
151
* @param count number of followers to get
151
- * @param nextCursor next cursor of the page
152
152
* @return list of followers
153
153
* @throws IOException if there's an error in the network
154
154
* @throws InstagramException if there's an error in the Instagram API
155
155
*/
156
- public List <String > getFollowers (int count , @ Nullable String nextCursor ) throws IOException , InstagramException {
157
- var req = Utils .createGetRequest ("friendships/" + pk + "/followers/?count=" + count + "&maxId=" + nextCursor ,authInfo );
156
+ public List <String > getFollowers (int count ) throws IOException , InstagramException {
157
+ var req = Utils .createGetRequest ("friendships/" + pk + "/followers/?count=" + count + "&maxId=" + nextPageCursor ,authInfo );
158
158
try (var response = Utils .call (req ,authInfo )){
159
159
var json = new JSONObject (response .body ().string ());
160
+ nextPageCursor = json .getString ("next_max_id" );
160
161
var list = new ArrayList <String >();
161
162
var users = json .getJSONArray ("users" );
162
163
for (int i = 0 ; i < users .length (); i ++) {
@@ -167,17 +168,17 @@ public List<String> getFollowers(int count,@Nullable String nextCursor) throws I
167
168
}
168
169
169
170
/**
170
- * Get the followings of the user
171
+ * Get the followings of the user. The method is auto paginated
171
172
* @param count number of followings to get
172
- * @param nextCursor next cursor of the page for pagination
173
173
* @return list of followings
174
174
* @throws IOException if there's an error in the network
175
175
* @throws InstagramException if there's an error in the Instagram API
176
176
*/
177
- public List <String > getFollowings (int count , @ Nullable String nextCursor ) throws IOException , InstagramException {
178
- var req = Utils .createGetRequest ("friendships/" + pk + "/following/?count=" + count + "&maxId=" + nextCursor ,authInfo );
177
+ public List <String > getFollowings (int count ) throws IOException , InstagramException {
178
+ var req = Utils .createGetRequest ("friendships/" + pk + "/following/?count=" + count + "&maxId=" + nextPageCursor ,authInfo );
179
179
try (var response = Utils .call (req ,authInfo )){
180
180
var json = new JSONObject (response .body ().string ());
181
+ nextPageCursor = json .getString ("next_max_id" );
181
182
var list = new ArrayList <String >();
182
183
var users = json .getJSONArray ("users" );
183
184
for (int i = 0 ; i < users .length (); i ++) {
0 commit comments