WebView 完成 OAuth 授權獲取 access_token 後,請求 Instagram API https://api.instagram.com/v1/users/self/media/recent?access_token=... 獲取用戶近期媒體,解析 JSON 提取縮略圖 URL。
access_token。data 數組,提取 images.thumbnail.url。String apiUrl = "https://api.instagram.com/v1/users/self/media/recent?access_token=" + accessToken;
URL url = new URL(apiUrl);
URLConnection conn = url.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) sb.append(line);
JSONObject json = new JSONObject(sb.toString());
JSONArray data = json.getJSONArray("data");
for (int i = 0; i < data.length(); i++) {
JSONObject item = data.getJSONObject(i);
JSONObject images = item.getJSONObject("images");
JSONObject thumbnail = images.getJSONObject("thumbnail");
String thumbUrl = thumbnail.getString("url");
// 保存或展示 thumbUrl
Log.i("Instagram", "Thumb: " + thumbUrl);
}
CLIENT_ID/CLIENT_SECRET。scope=basic仅能获取基础媒体信息。OAuth 流程 + API 請求 + JSON 解析,三步獲取用戶 Instagram 照片。