Instagram: [standard_resolution] is not a JSONObject.

This commit is contained in:
Jozsef.Kerekes 2017-10-06 20:45:22 +03:00 committed by metaprime
parent 3a70c6f5ab
commit 7587961e90

View File

@ -138,9 +138,15 @@ public class InstagramRipper extends AbstractJSONRipper {
private String getMedia(JSONObject data) { private String getMedia(JSONObject data) {
String imageURL = ""; String imageURL = "";
if (data.has("videos")) { if (data.has("videos")) {
imageURL = data.getJSONObject("videos").getJSONObject("standard_resolution").getString("url"); JSONObject videosObject = data.getJSONObject("videos");
if (!videosObject.isNull("standard_resolution")) {
imageURL = videosObject.getJSONObject("standard_resolution").getString("url");
}
} else if (data.has("images")) { } else if (data.has("images")) {
imageURL = data.getJSONObject("images").getJSONObject("standard_resolution").getString("url"); JSONObject imagesObject = data.getJSONObject("images");
if (!imagesObject.isNull("standard_resolution")) {
imageURL = imagesObject.getJSONObject("standard_resolution").getString("url");
}
} }
return imageURL; return imageURL;
} }
@ -158,14 +164,14 @@ public class InstagramRipper extends AbstractJSONRipper {
for (int carouselIndex = 0; carouselIndex < carouselMedias.length(); carouselIndex++) { for (int carouselIndex = 0; carouselIndex < carouselMedias.length(); carouselIndex++) {
JSONObject carouselMedia = (JSONObject) carouselMedias.get(carouselIndex); JSONObject carouselMedia = (JSONObject) carouselMedias.get(carouselIndex);
String imageURL = getMedia(carouselMedia); String imageURL = getMedia(carouselMedia);
if (!imageURL.equals("")) { if (!"".equals(imageURL)) {
imageURL = getOriginalUrl(imageURL); imageURL = getOriginalUrl(imageURL);
imageURLs.add(imageURL); imageURLs.add(imageURL);
} }
} }
} else { } else {
String imageURL = getMedia(data); String imageURL = getMedia(data);
if (!imageURL.equals("")) { if (!"".equals(imageURL)) {
imageURL = getOriginalUrl(imageURL); imageURL = getOriginalUrl(imageURL);
imageURLs.add(imageURL); imageURLs.add(imageURL);
} }