diff --git a/pom.xml b/pom.xml index 70d7934..0a064b0 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.0 + 3.8.1 1.8 1.8 @@ -25,7 +25,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.2.0 + 3.2.2 @@ -66,7 +66,7 @@ com.squareup.okhttp3 okhttp - 3.12.0 + 4.4.0 org.projectlombok @@ -78,13 +78,13 @@ commons-beanutils commons-beanutils - 1.9.3 + 1.9.4 org.eclipse.persistence org.eclipse.persistence.moxy - 2.5.0 + 2.7.6 @@ -96,44 +96,44 @@ commons-io commons-io - 2.6 + 2.7 com.github.igor-suhorukov dom-transformation - 1.1 + 1.2 com.fasterxml.jackson.core jackson-databind - 2.9.7 + 2.10.0.pr1 com.squareup.okhttp3 logging-interceptor - 3.11.0 + 4.4.0 org.assertj assertj-core - 3.11.1 + 3.15.0 test javax.xml.bind jaxb-api - 2.1 + 2.3.1 junit junit - 4.12 + 4.13.1 test diff --git a/src/main/java/me/postaddict/instagram/scraper/AuthenticatedInsta.java b/src/main/java/me/postaddict/instagram/scraper/AuthenticatedInsta.java index 91e0238..320229f 100644 --- a/src/main/java/me/postaddict/instagram/scraper/AuthenticatedInsta.java +++ b/src/main/java/me/postaddict/instagram/scraper/AuthenticatedInsta.java @@ -25,4 +25,6 @@ public interface AuthenticatedInsta extends AnonymousInsta { PageObject getFollowers(long userId, int pageCount) throws IOException; ActivityFeed getActivityFeed() throws IOException; + + Long getLoginUserId(); } diff --git a/src/main/java/me/postaddict/instagram/scraper/ErrorType.java b/src/main/java/me/postaddict/instagram/scraper/ErrorType.java new file mode 100644 index 0000000..3e45fc3 --- /dev/null +++ b/src/main/java/me/postaddict/instagram/scraper/ErrorType.java @@ -0,0 +1,22 @@ +package me.postaddict.instagram.scraper; + +public enum ErrorType { + + CHECKPOINT_REQUIRED, + + TWO_FACTOR_REQUIRED, + + UNAUTHORIZED, + + TEMPORARY_ACTION_BLOCKED, + + ACTION_BLOCKED, + + FOLLOWING_THE_MAX_LIMIT_OF_ACCOUNTS, + + RATE_LIMITED, + + INSTAGRAM_SERVER_ERROR, + + UNKNOWN_ERROR +} diff --git a/src/main/java/me/postaddict/instagram/scraper/Instagram.java b/src/main/java/me/postaddict/instagram/scraper/Instagram.java index 09d3179..ed12c7f 100644 --- a/src/main/java/me/postaddict/instagram/scraper/Instagram.java +++ b/src/main/java/me/postaddict/instagram/scraper/Instagram.java @@ -30,7 +30,9 @@ import me.postaddict.instagram.scraper.request.parameters.MediaCode; import me.postaddict.instagram.scraper.request.parameters.TagName; import me.postaddict.instagram.scraper.request.parameters.UserParameter; +import okhttp3.Cookie; import okhttp3.FormBody; +import okhttp3.HttpUrl; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; @@ -53,8 +55,10 @@ public Instagram(OkHttpClient httpClient) { protected Request withCsrfToken(Request request) { return request.newBuilder() - .addHeader("X-CSRFToken", csrf_token) + .addHeader("X-CSRFToken", getCSRFToken()) .addHeader("X-Instagram-AJAX", (rollout_hash.isEmpty() ? "1" : rollout_hash)) + .addHeader("X-Requested-With", "XMLHttpRequest") + .addHeader("X-IG-App-ID", "936619743392459") .build(); } @@ -76,6 +80,15 @@ private void getCSRFToken(ResponseBody body) throws IOException { this.csrf_token=getToken("\"csrf_token\":\"",32,body.byteStream()); } + private String getCSRFToken() { + for (Cookie cookie : this.httpClient.cookieJar().loadForRequest(HttpUrl.parse(Endpoint.BASE_URL))) { + if ("csrftoken".equals(cookie.name())) { + return cookie.value(); + } + } + return csrf_token; + } + private void getRolloutHash(ResponseBody body){ try { this.rollout_hash=getToken("\"rollout_hash\":\"",12,body.byteStream()); @@ -107,18 +120,20 @@ public void login(String username, String password) throws IOException { RequestBody formBody = new FormBody.Builder() .add("username", username) .add("password", password) + .add("queryParams", "{}") + .add("optIntoOneTap", "true") .build(); Request request = new Request.Builder() .url(Endpoint.LOGIN_URL) - .header(Endpoint.REFERER, Endpoint.BASE_URL + "/") + .header(Endpoint.REFERER, Endpoint.BASE_URL + "/accounts/login/") .post(formBody) .build(); Response response = executeHttpRequest(withCsrfToken(request)); try(InputStream jsonStream = response.body().byteStream()) { if(!mapper.isAuthenticated(jsonStream)){ - throw new InstagramAuthException("Credentials rejected by instagram"); + throw new InstagramAuthException("Credentials rejected by instagram", ErrorType.UNAUTHORIZED); } } } @@ -130,7 +145,7 @@ public Account getAccountById(long id) throws IOException { .build(); Response response = executeHttpRequest(withCsrfToken(request)); try(InputStream jsonStream = response.body().byteStream()) { - return getMediaByCode(mapper.getLastMediaShortCode(jsonStream)).getOwner(); + return getAccountByUsername(getMediaByCode(mapper.getLastMediaShortCode(jsonStream)).getOwner().getUsername()); } } @@ -344,4 +359,14 @@ private void validateTagName(String tag) { throw new IllegalArgumentException("Please provide non empty tag name that not starts with #"); } } + + @Override + public Long getLoginUserId() { + for (Cookie cookie : this.httpClient.cookieJar().loadForRequest(HttpUrl.parse(Endpoint.BASE_URL))) { + if ("ds_user_id".equals(cookie.name())) { + return Long.parseLong(cookie.value()); + } + } + return null; + } } diff --git a/src/main/java/me/postaddict/instagram/scraper/InstagramFactory.java b/src/main/java/me/postaddict/instagram/scraper/InstagramFactory.java index 425548c..0a0250f 100644 --- a/src/main/java/me/postaddict/instagram/scraper/InstagramFactory.java +++ b/src/main/java/me/postaddict/instagram/scraper/InstagramFactory.java @@ -4,7 +4,7 @@ import me.postaddict.instagram.scraper.cookie.CookieHashSet; import me.postaddict.instagram.scraper.cookie.DefaultCookieJar; import me.postaddict.instagram.scraper.interceptor.ErrorInterceptor; -import me.postaddict.instagram.scraper.interceptor.UserAgentInterceptor; +import me.postaddict.instagram.scraper.interceptor.FakeBrowserInterceptor; import okhttp3.OkHttpClient; import java.io.IOException; @@ -16,7 +16,7 @@ public static Instagram getAuthenticatedInstagramClient(String login, String pas throws IOException{ OkHttpClient httpClient = new OkHttpClient.Builder() - .addInterceptor(new UserAgentInterceptor(userAgent)) + .addInterceptor(new FakeBrowserInterceptor(userAgent)) .addInterceptor(new ErrorInterceptor()) .cookieJar(new DefaultCookieJar(new CookieHashSet())) .build(); diff --git a/src/main/java/me/postaddict/instagram/scraper/exception/InstagramAuthException.java b/src/main/java/me/postaddict/instagram/scraper/exception/InstagramAuthException.java index f1a3f64..79725c4 100644 --- a/src/main/java/me/postaddict/instagram/scraper/exception/InstagramAuthException.java +++ b/src/main/java/me/postaddict/instagram/scraper/exception/InstagramAuthException.java @@ -1,10 +1,17 @@ package me.postaddict.instagram.scraper.exception; +import me.postaddict.instagram.scraper.ErrorType; + public class InstagramAuthException extends InstagramException { - public InstagramAuthException(){} + public InstagramAuthException() { + } public InstagramAuthException(String message) { - super(message); + super(message, ErrorType.UNKNOWN_ERROR); + } + + public InstagramAuthException(String message, ErrorType errorType) { + super(message, errorType); } } diff --git a/src/main/java/me/postaddict/instagram/scraper/exception/InstagramException.java b/src/main/java/me/postaddict/instagram/scraper/exception/InstagramException.java index d464de8..bb16e68 100644 --- a/src/main/java/me/postaddict/instagram/scraper/exception/InstagramException.java +++ b/src/main/java/me/postaddict/instagram/scraper/exception/InstagramException.java @@ -2,12 +2,26 @@ import java.io.IOException; +import me.postaddict.instagram.scraper.ErrorType; + public class InstagramException extends IOException { + + private ErrorType errorType; public InstagramException() { } - public InstagramException(String message) { + public InstagramException(String message, ErrorType errorType) { super(message); + this.errorType = errorType; + } + + public ErrorType getErrorType() { + return errorType; + } + + @Override + public String getMessage() { + return super.getMessage() + " : " + getErrorType(); } } diff --git a/src/main/java/me/postaddict/instagram/scraper/exception/InstagramNotFoundException.java b/src/main/java/me/postaddict/instagram/scraper/exception/InstagramNotFoundException.java index 48c8438..9c3119e 100644 --- a/src/main/java/me/postaddict/instagram/scraper/exception/InstagramNotFoundException.java +++ b/src/main/java/me/postaddict/instagram/scraper/exception/InstagramNotFoundException.java @@ -1,11 +1,17 @@ package me.postaddict.instagram.scraper.exception; +import me.postaddict.instagram.scraper.ErrorType; + public class InstagramNotFoundException extends InstagramException { public InstagramNotFoundException() { } public InstagramNotFoundException(String message) { - super(message); + super(message, ErrorType.UNKNOWN_ERROR); + } + + public InstagramNotFoundException(String message, ErrorType errorType) { + super(message, errorType); } } diff --git a/src/main/java/me/postaddict/instagram/scraper/interceptor/ErrorInterceptor.java b/src/main/java/me/postaddict/instagram/scraper/interceptor/ErrorInterceptor.java index 0da8890..09aae75 100644 --- a/src/main/java/me/postaddict/instagram/scraper/interceptor/ErrorInterceptor.java +++ b/src/main/java/me/postaddict/instagram/scraper/interceptor/ErrorInterceptor.java @@ -1,5 +1,6 @@ package me.postaddict.instagram.scraper.interceptor; +import me.postaddict.instagram.scraper.ErrorType; import me.postaddict.instagram.scraper.exception.InstagramAuthException; import me.postaddict.instagram.scraper.exception.InstagramException; import me.postaddict.instagram.scraper.exception.InstagramNotFoundException; @@ -17,18 +18,43 @@ public Response intercept(Chain chain) throws IOException { if (code == 200) { return response; } else { + String bodyString = String.valueOf(response.body().string()); response.body().close(); - } - switch (code) { - case 401: - throw new InstagramAuthException("Unauthorized"); - case 403: - throw new InstagramAuthException("Access denied"); - case 404: - throw new InstagramNotFoundException("Resource does not exist"); - default: - throw new InstagramException("Response code is not equal 200. Something went wrong. Please report issue."); + ErrorType errorType = ErrorType.UNKNOWN_ERROR; + switch (code) { + case 400: + if (bodyString.contains("Sorry, you're following the max limit of accounts.")) { + errorType = ErrorType.FOLLOWING_THE_MAX_LIMIT_OF_ACCOUNTS; + } else if (bodyString.contains("feedback_required") || + bodyString.contains("Action Blocked") || + bodyString.contains("\\u30d6\\u30ed\\u30c3\\u30af\\u3055\\u308c\\u3066\\u3044\\u307e\\u3059")) { + errorType = ErrorType.ACTION_BLOCKED; + } else if (bodyString.contains("checkpoint_required")) { + errorType = ErrorType.CHECKPOINT_REQUIRED; + } else if (bodyString.contains("two_factor_required")) { + errorType = ErrorType.TWO_FACTOR_REQUIRED; + } + throw new InstagramException("Bad Request", errorType); + case 401: + throw new InstagramAuthException("Unauthorized", ErrorType.UNAUTHORIZED); + case 403: + if (bodyString.contains("Please wait a few minutes before you try again.") || + bodyString.contains("数分してからもう一度実行してください。")) { + errorType = ErrorType.TEMPORARY_ACTION_BLOCKED; + } else if (bodyString.contains("unauthorized")) { + errorType = ErrorType.UNAUTHORIZED; + } + throw new InstagramAuthException("Access denied", errorType); + case 404: + throw new InstagramNotFoundException("Resource does not exist", errorType); + case 429: + throw new InstagramException("Rate limited", ErrorType.RATE_LIMITED); + case 502: + throw new InstagramException("Bad Gateway", ErrorType.INSTAGRAM_SERVER_ERROR); + default: + throw new InstagramException("Response code is " + code + ".", errorType); + } } } } diff --git a/src/main/java/me/postaddict/instagram/scraper/interceptor/UserAgentInterceptor.java b/src/main/java/me/postaddict/instagram/scraper/interceptor/FakeBrowserInterceptor.java similarity index 70% rename from src/main/java/me/postaddict/instagram/scraper/interceptor/UserAgentInterceptor.java rename to src/main/java/me/postaddict/instagram/scraper/interceptor/FakeBrowserInterceptor.java index c55572c..e318f0a 100644 --- a/src/main/java/me/postaddict/instagram/scraper/interceptor/UserAgentInterceptor.java +++ b/src/main/java/me/postaddict/instagram/scraper/interceptor/FakeBrowserInterceptor.java @@ -6,11 +6,11 @@ import java.io.IOException; -public class UserAgentInterceptor implements Interceptor { +public class FakeBrowserInterceptor implements Interceptor { private final String userAgent; - public UserAgentInterceptor(String userAgent) { + public FakeBrowserInterceptor(String userAgent) { this.userAgent = userAgent; } @@ -23,6 +23,9 @@ public Response intercept(Chain chain) throws IOException { Request originalRequest = chain.request(); Request newRequest = originalRequest.newBuilder() .header("User-Agent", userAgent) + .header("Accept", "*/*") + .header("Accept-Language", "ja,en-US;q=0.7,en;q=0.3") + .header("DNT", "1") .build(); return chain.proceed(newRequest); } diff --git a/src/main/java/me/postaddict/instagram/scraper/mapper/ModelMapper.java b/src/main/java/me/postaddict/instagram/scraper/mapper/ModelMapper.java index 9900d72..6277d21 100644 --- a/src/main/java/me/postaddict/instagram/scraper/mapper/ModelMapper.java +++ b/src/main/java/me/postaddict/instagram/scraper/mapper/ModelMapper.java @@ -48,7 +48,9 @@ public Media mapMedia(InputStream jsonStream){ GraphQlResponse graphQlResponse = mapObject(jsonStream, "me/postaddict/instagram/scraper/model/media-by-url.json"); Media media = graphQlResponse.getPayload(); - media.setCommentCount(media.getCommentPreview().getCount()); + if (media.getCommentPreview() != null) { + media.setCommentCount(media.getCommentPreview().getCount()); + } if(media.getCommentPreview()!=null && media.getCommentPreview().getNodes()!=null) { media.getCommentPreview().getNodes().forEach(this::updateCommentTime); } diff --git a/src/main/java/me/postaddict/instagram/scraper/model/Account.java b/src/main/java/me/postaddict/instagram/scraper/model/Account.java index bdbd003..9ad5723 100644 --- a/src/main/java/me/postaddict/instagram/scraper/model/Account.java +++ b/src/main/java/me/postaddict/instagram/scraper/model/Account.java @@ -40,4 +40,5 @@ public class Account { @Transient private PageObject media; private Date lastUpdated = new Date(); + private Boolean isBusinessAccount; } diff --git a/src/main/resources/me/postaddict/instagram/scraper/model/account-binding.json b/src/main/resources/me/postaddict/instagram/scraper/model/account-binding.json index 76d850b..b36daa1 100644 --- a/src/main/resources/me/postaddict/instagram/scraper/model/account-binding.json +++ b/src/main/resources/me/postaddict/instagram/scraper/model/account-binding.json @@ -35,7 +35,8 @@ {"java-attribute": "profilePicUrlHd", "type": "java.lang.String", "xml-path": "profile_pic_url_hd/text()"}, {"java-attribute": "requestedByViewer", "type": "java.lang.Boolean", "xml-path": "requested_by_viewer/text()"}, {"java-attribute": "connectedFbPage", "type": "java.lang.String", "xml-path": "connected_fb_page/text()"}, - {"java-attribute": "media", "type": "me.postaddict.instagram.scraper.model.PageObject", "xml-path": "edge_owner_to_timeline_media"} + {"java-attribute": "media", "type": "me.postaddict.instagram.scraper.model.PageObject", "xml-path": "edge_owner_to_timeline_media"}, + {"java-attribute": "isBusinessAccount", "type": "java.lang.String", "xml-path": "is_business_account/text()"} ] } }, diff --git a/src/main/resources/me/postaddict/instagram/scraper/model/comments.json b/src/main/resources/me/postaddict/instagram/scraper/model/comments.json index 9ca681c..6c6ccc1 100644 --- a/src/main/resources/me/postaddict/instagram/scraper/model/comments.json +++ b/src/main/resources/me/postaddict/instagram/scraper/model/comments.json @@ -9,7 +9,7 @@ }, "java-attributes": { "xml-element": [ - {"java-attribute": "payload","type": "me.postaddict.instagram.scraper.model.PageObject","xml-path": "shortcode_media/edge_media_to_comment"} + {"java-attribute": "payload","type": "me.postaddict.instagram.scraper.model.PageObject","xml-path": "shortcode_media/edge_media_to_parent_comment"} ] } }, diff --git a/src/main/resources/me/postaddict/instagram/scraper/model/location.json b/src/main/resources/me/postaddict/instagram/scraper/model/location.json index 080cc7f..abef151 100644 --- a/src/main/resources/me/postaddict/instagram/scraper/model/location.json +++ b/src/main/resources/me/postaddict/instagram/scraper/model/location.json @@ -66,7 +66,7 @@ {"java-attribute": "commentsDisabled","type": "java.lang.Boolean","xml-path": "comments_disabled/text()"}, {"java-attribute": "takenAtTimestamp","type": "java.lang.String","xml-path": "taken_at_timestamp/text()"}, {"java-attribute": "caption","type": "java.lang.String","xml-path": "edge_media_to_caption/edges/node/text/text()"}, - {"java-attribute": "commentCount","type": "java.lang.Integer","xml-path": "edge_media_to_comment/count/text()"}, + {"java-attribute": "commentCount","type": "java.lang.Integer","xml-path": "edge_media_to_parent_comment/count/text()"}, {"java-attribute": "likeCount","type": "java.lang.Integer","xml-path": "edge_liked_by/count/text()"}, {"java-attribute": "width","type": "java.lang.Integer","xml-path": "dimensions/width/text()"}, {"java-attribute": "height","type": "java.lang.Integer","xml-path": "dimensions/height/text()"}, diff --git a/src/main/resources/me/postaddict/instagram/scraper/model/media-by-url.json b/src/main/resources/me/postaddict/instagram/scraper/model/media-by-url.json index 8af2eec..80f3b52 100644 --- a/src/main/resources/me/postaddict/instagram/scraper/model/media-by-url.json +++ b/src/main/resources/me/postaddict/instagram/scraper/model/media-by-url.json @@ -73,10 +73,10 @@ {"java-attribute": "isAdvertising","type": "java.lang.Boolean","xml-path": "is_ad/text()"}, {"java-attribute": "gatingInfo","type": "java.lang.String","xml-path": "gating_info/text()"}, {"java-attribute": "caption","type": "java.lang.String","xml-path": "edge_media_to_caption/edges/node/text/text()"}, - {"java-attribute": "commentCount","type": "java.lang.Integer","xml-path": "edge_media_to_comment/count/text()"}, + {"java-attribute": "commentCount","type": "java.lang.Integer","xml-path": "edge_media_to_parent_comment/count/text()"}, {"java-attribute": "likeCount","type": "java.lang.Integer","xml-path": "edge_media_preview_like/count/text()"}, {"java-attribute": "firstLikes","type": "me.postaddict.instagram.scraper.model.Account","xml-path": "edge_media_preview_like/edges/node"}, - {"java-attribute": "commentPreview","type": "me.postaddict.instagram.scraper.model.PageObject","xml-path": "edge_media_to_comment"}, + {"java-attribute": "commentPreview","type": "me.postaddict.instagram.scraper.model.PageObject","xml-path": "edge_media_to_parent_comment"}, {"java-attribute": "carouselMedia","type": "me.postaddict.instagram.scraper.model.CarouselResource","xml-path": "edge_sidecar_to_children/edges/node"}, {"java-attribute": "takenAtTimestamp","type": "java.lang.Long","xml-path": "taken_at_timestamp/text()"}, diff --git a/src/main/resources/me/postaddict/instagram/scraper/model/medias.json b/src/main/resources/me/postaddict/instagram/scraper/model/medias.json index 5b06948..b54c177 100644 --- a/src/main/resources/me/postaddict/instagram/scraper/model/medias.json +++ b/src/main/resources/me/postaddict/instagram/scraper/model/medias.json @@ -45,7 +45,7 @@ {"java-attribute": "commentsDisabled","type": "java.lang.Boolean","xml-path": "comments_disabled/text()"}, {"java-attribute": "gatingInfo","type": "java.lang.String","xml-path": "gating_info/text()"}, {"java-attribute": "caption","type": "java.lang.String","xml-path": "edge_media_to_caption/edges/node/text/text()"}, - {"java-attribute": "commentCount","type": "java.lang.Integer","xml-path": "edge_media_to_comment/count/text()"}, + {"java-attribute": "commentCount","type": "java.lang.Integer","xml-path": "edge_media_to_parent_comment/count/text()"}, {"java-attribute": "likeCount","type": "java.lang.Integer","xml-path": "edge_media_preview_like/count/text()"}, {"java-attribute": "takenAtTimestamp","type": "java.lang.Long","xml-path": "taken_at_timestamp/text()"}, {"java-attribute": "width","type": "java.lang.Integer","xml-path": "dimensions/width/text()"}, diff --git a/src/main/resources/me/postaddict/instagram/scraper/model/tag.json b/src/main/resources/me/postaddict/instagram/scraper/model/tag.json index bb360b1..8928e2d 100644 --- a/src/main/resources/me/postaddict/instagram/scraper/model/tag.json +++ b/src/main/resources/me/postaddict/instagram/scraper/model/tag.json @@ -63,7 +63,7 @@ {"java-attribute": "commentsDisabled","type": "java.lang.Boolean","xml-path": "comments_disabled/text()"}, {"java-attribute": "takenAtTimestamp","type": "java.lang.String","xml-path": "taken_at_timestamp/text()"}, {"java-attribute": "caption","type": "java.lang.String","xml-path": "edge_media_to_caption/edges/node/text/text()"}, - {"java-attribute": "commentCount","type": "java.lang.Integer","xml-path": "edge_media_to_comment/count/text()"}, + {"java-attribute": "commentCount","type": "java.lang.Integer","xml-path": "edge_media_to_parent_comment/count/text()"}, {"java-attribute": "likeCount","type": "java.lang.Integer","xml-path": "edge_liked_by/count/text()"}, {"java-attribute": "width","type": "java.lang.Integer","xml-path": "dimensions/width/text()"}, {"java-attribute": "height","type": "java.lang.Integer","xml-path": "dimensions/height/text()"}, diff --git a/src/test/java/me/postaddict/instagram/scraper/AnonymousInstaTest.java b/src/test/java/me/postaddict/instagram/scraper/AnonymousInstaTest.java index cffd637..22f11c1 100644 --- a/src/test/java/me/postaddict/instagram/scraper/AnonymousInstaTest.java +++ b/src/test/java/me/postaddict/instagram/scraper/AnonymousInstaTest.java @@ -3,7 +3,7 @@ import me.postaddict.instagram.scraper.cookie.CookieHashSet; import me.postaddict.instagram.scraper.cookie.DefaultCookieJar; import me.postaddict.instagram.scraper.interceptor.ErrorInterceptor; -import me.postaddict.instagram.scraper.interceptor.UserAgentInterceptor; +import me.postaddict.instagram.scraper.interceptor.FakeBrowserInterceptor; import me.postaddict.instagram.scraper.interceptor.UserAgents; import static org.assertj.core.api.Assertions.*; import me.postaddict.instagram.scraper.model.*; @@ -30,7 +30,7 @@ public static void setUp() throws Exception { loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient httpClient = new OkHttpClient.Builder() .addNetworkInterceptor(loggingInterceptor) - .addInterceptor(new UserAgentInterceptor(UserAgents.OSX_CHROME)) + .addInterceptor(new FakeBrowserInterceptor(UserAgents.OSX_CHROME)) .addInterceptor(new ErrorInterceptor()) .cookieJar(new DefaultCookieJar(new CookieHashSet())) .build(); diff --git a/src/test/java/me/postaddict/instagram/scraper/AuthenticatedInstaTest.java b/src/test/java/me/postaddict/instagram/scraper/AuthenticatedInstaTest.java index e691a39..3c2e751 100644 --- a/src/test/java/me/postaddict/instagram/scraper/AuthenticatedInstaTest.java +++ b/src/test/java/me/postaddict/instagram/scraper/AuthenticatedInstaTest.java @@ -4,7 +4,7 @@ import me.postaddict.instagram.scraper.cookie.DefaultCookieJar; import me.postaddict.instagram.scraper.exception.InstagramAuthException; import me.postaddict.instagram.scraper.interceptor.ErrorInterceptor; -import me.postaddict.instagram.scraper.interceptor.UserAgentInterceptor; +import me.postaddict.instagram.scraper.interceptor.FakeBrowserInterceptor; import me.postaddict.instagram.scraper.interceptor.UserAgents; import me.postaddict.instagram.scraper.model.*; import okhttp3.OkHttpClient; @@ -31,7 +31,7 @@ public static void setUp() throws Exception { loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS); OkHttpClient httpClient = new OkHttpClient.Builder() .addNetworkInterceptor(loggingInterceptor) - .addInterceptor(new UserAgentInterceptor(UserAgents.OSX_CHROME)) + .addInterceptor(new FakeBrowserInterceptor(UserAgents.OSX_CHROME)) .addInterceptor(new ErrorInterceptor()) .cookieJar(new DefaultCookieJar(new CookieHashSet())) .build(); @@ -47,7 +47,7 @@ public void testLoginWithInvalidCredentials() throws Exception { loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS); OkHttpClient httpClient = new OkHttpClient.Builder() .addNetworkInterceptor(loggingInterceptor) - .addInterceptor(new UserAgentInterceptor(UserAgents.OSX_CHROME)) + .addInterceptor(new FakeBrowserInterceptor(UserAgents.OSX_CHROME)) .addInterceptor(new ErrorInterceptor()) .cookieJar(new DefaultCookieJar(new CookieHashSet())) .build(); diff --git a/src/test/java/me/postaddict/instagram/scraper/MultiThreadTest.java b/src/test/java/me/postaddict/instagram/scraper/MultiThreadTest.java index ee32ea4..9d3f023 100644 --- a/src/test/java/me/postaddict/instagram/scraper/MultiThreadTest.java +++ b/src/test/java/me/postaddict/instagram/scraper/MultiThreadTest.java @@ -3,7 +3,7 @@ import me.postaddict.instagram.scraper.cookie.CookieHashSet; import me.postaddict.instagram.scraper.cookie.DefaultCookieJar; import me.postaddict.instagram.scraper.interceptor.ErrorInterceptor; -import me.postaddict.instagram.scraper.interceptor.UserAgentInterceptor; +import me.postaddict.instagram.scraper.interceptor.FakeBrowserInterceptor; import me.postaddict.instagram.scraper.interceptor.UserAgents; import me.postaddict.instagram.scraper.model.Media; import okhttp3.OkHttpClient; @@ -35,7 +35,7 @@ public static void setUp() throws Exception { loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient httpClient = new OkHttpClient.Builder() .addNetworkInterceptor(loggingInterceptor) - .addInterceptor(new UserAgentInterceptor(UserAgents.OSX_CHROME)) + .addInterceptor(new FakeBrowserInterceptor(UserAgents.OSX_CHROME)) .addInterceptor(new ErrorInterceptor()) .cookieJar(new DefaultCookieJar(new CookieHashSet())) .build(); diff --git a/src/test/java/me/postaddict/instagram/scraper/StatelessInstaTest.java b/src/test/java/me/postaddict/instagram/scraper/StatelessInstaTest.java index 4f39fc8..f8c3819 100644 --- a/src/test/java/me/postaddict/instagram/scraper/StatelessInstaTest.java +++ b/src/test/java/me/postaddict/instagram/scraper/StatelessInstaTest.java @@ -1,7 +1,7 @@ package me.postaddict.instagram.scraper; import me.postaddict.instagram.scraper.interceptor.ErrorInterceptor; -import me.postaddict.instagram.scraper.interceptor.UserAgentInterceptor; +import me.postaddict.instagram.scraper.interceptor.FakeBrowserInterceptor; import me.postaddict.instagram.scraper.interceptor.UserAgents; import me.postaddict.instagram.scraper.model.Account; import me.postaddict.instagram.scraper.model.Media; @@ -29,7 +29,7 @@ public static void setUp() throws Exception { loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS); OkHttpClient httpClient = new OkHttpClient.Builder() .addNetworkInterceptor(loggingInterceptor) - .addInterceptor(new UserAgentInterceptor(UserAgents.OSX_CHROME)) + .addInterceptor(new FakeBrowserInterceptor(UserAgents.OSX_CHROME)) .addInterceptor(new ErrorInterceptor()) .build(); client = new Instagram(httpClient);