From ec592074be0511dca5dfd918595bd6cf70f97d44 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Sat, 27 Mar 2021 10:41:31 -0400 Subject: [PATCH] fix graphql parse thumbnail --- .../instagrabber/utils/ResponseBodyUtils.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/utils/ResponseBodyUtils.java b/app/src/main/java/awais/instagrabber/utils/ResponseBodyUtils.java index 3c5eb0f6..2722d11e 100644 --- a/app/src/main/java/awais/instagrabber/utils/ResponseBodyUtils.java +++ b/app/src/main/java/awais/instagrabber/utils/ResponseBodyUtils.java @@ -729,15 +729,19 @@ public final class ResponseBodyUtils { width = dimensions.optInt("width"); } String thumbnailUrl = null; - final JSONArray displayResources = feedItem.getJSONArray("display_resources"); final List candidates = new ArrayList(); - for (int i = 0; i < displayResources.length(); i++) { - final JSONObject displayResource = displayResources.getJSONObject(i); - candidates.add(new MediaCandidate( - displayResource.getInt("config_width"), - displayResource.getInt("config_height"), - displayResource.getString("src") - )); + if (feedItem.has("display_resources") || feedItem.has("thumbnail_resources")) { + final JSONArray displayResources = feedItem.has("display_resources") + ? feedItem.getJSONArray("display_resources") + : feedItem.getJSONArray("thumbnail_resources"); + for (int i = 0; i < displayResources.length(); i++) { + final JSONObject displayResource = displayResources.getJSONObject(i); + candidates.add(new MediaCandidate( + displayResource.getInt("config_width"), + displayResource.getInt("config_height"), + displayResource.getString("src") + )); + } } final ImageVersions2 imageVersions2 = new ImageVersions2(candidates);