Skip to content

Commit aa7b891

Browse files
authored
update 0.1
1 parent d9c7eec commit aa7b891

File tree

3 files changed

+12
-21
lines changed

3 files changed

+12
-21
lines changed

JxInsta/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ java {
77
targetCompatibility = JavaVersion.VERSION_17
88
}
99

10+
1011
dependencies {
1112
implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '5.0.0-alpha.11'
1213
implementation 'com.github.ErrorxCode:JSON-java-port:20220320'
1314

14-
}
15+
}

JxInsta/src/main/java/com/errorxcode/jxinsta/AuthInfo.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,11 @@ public class AuthInfo {
99
public String authorization;
1010
public JxInsta.LoginType loginType;
1111

12-
public static AuthInfo forMobile(@NotNull String bearerToken) {
12+
protected static AuthInfo forMobile(@NotNull String bearerToken) {
1313
var info = new AuthInfo();
1414
info.token = bearerToken;
1515
info.authorization = bearerToken;
1616
info.loginType = JxInsta.LoginType.APP_AUTHENTICATION;
1717
return info;
1818
}
19-
20-
@Override
21-
public String toString() {
22-
return "AuthInfo{" +
23-
"crsf='" + crsf + '\'' +
24-
", token='" + token + '\'' +
25-
", cookie='" + cookie + '\'' +
26-
", authorization='" + authorization + '\'' +
27-
", loginType=" + loginType +
28-
'}';
29-
}
3019
}

JxInsta/src/main/java/com/errorxcode/jxinsta/endpoints/profile/Profile.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
public class Profile {
3333
protected final AuthInfo authInfo;
3434
public String posts_end_cursor;
35+
private String nextPageCursor;
3536
public String username;
3637
public long pk;
3738
public String full_name;
@@ -146,17 +147,17 @@ public static List<Post> _getPosts(@Nullable AuthInfo authInfo,long pk,@Nullable
146147
}
147148

148149
/**
149-
* Get the followers of the user
150+
* Get the followers of the user. The method is auto paginated
150151
* @param count number of followers to get
151-
* @param nextCursor next cursor of the page
152152
* @return list of followers
153153
* @throws IOException if there's an error in the network
154154
* @throws InstagramException if there's an error in the Instagram API
155155
*/
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);
158158
try (var response = Utils.call(req,authInfo)){
159159
var json = new JSONObject(response.body().string());
160+
nextPageCursor = json.getString("next_max_id");
160161
var list = new ArrayList<String>();
161162
var users = json.getJSONArray("users");
162163
for (int i = 0; i < users.length(); i++) {
@@ -167,17 +168,17 @@ public List<String> getFollowers(int count,@Nullable String nextCursor) throws I
167168
}
168169

169170
/**
170-
* Get the followings of the user
171+
* Get the followings of the user. The method is auto paginated
171172
* @param count number of followings to get
172-
* @param nextCursor next cursor of the page for pagination
173173
* @return list of followings
174174
* @throws IOException if there's an error in the network
175175
* @throws InstagramException if there's an error in the Instagram API
176176
*/
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);
179179
try (var response = Utils.call(req,authInfo)){
180180
var json = new JSONObject(response.body().string());
181+
nextPageCursor = json.getString("next_max_id");
181182
var list = new ArrayList<String>();
182183
var users = json.getJSONArray("users");
183184
for (int i = 0; i < users.length(); i++) {

0 commit comments

Comments
 (0)