android: how to get user photos in Instagram?
12,072
Solution 1
try this code i got solution from this:
URL example = new URL("https://api.instagram.com/v1/users/self/media/recent?access_token="
+ accessToken);
URLConnection tc = example.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
tc.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
JSONObject ob = new JSONObject(line);
JSONArray object = ob.getJSONArray("data");
for (int i = 0; i < object.length(); i++) {
JSONObject jo = (JSONObject) object.get(i);
JSONObject nja = (JSONObject) jo.getJSONObject(photos);
JSONObject purl3 = (JSONObject) nja
.getJSONObject("thumbnail");
Log.i(TAG, "" + purl3.getString("url"));
}
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
Solution 2
GET /users/[USER_ID]/media/recent/?access_token=[ACCESS_TOKEN]
You can hit this URL to get the user's feed (last 20 photos). This will give you a JSON array that you will then need to parse and display as desired in your app.
Related videos on Youtube
Author by
SubbaReddy PolamReddy
Updated on June 04, 2022Comments
-
SubbaReddy PolamReddy about 2 years
In my app my requirement is to get the user photos and show in my app.
For that i am authenticate , got access token and enter username password but that shows you don't have permission to open this page. next how can i get user profile and photos.
here my code is:
String url ="https://instagram.com/oauth/authorize?" +"response_type=token" + "&redirect_uri=" + CALLBACK_URL+"&scope=basic"+"&client_id=" + CLIENT_ID ; WebView webview = (WebView)findViewById(R.id.webview); webview.setWebViewClient(new WebViewClient() { public void onPageStarted(WebView view, String url, Bitmap favicon) { String fragment = "#access_token="; int start = url.indexOf(fragment); if (start > -1) { // You can use the accessToken for api calls now. String accessToken = url.substring(start + fragment.length(), url.length()); Log.v(TAG, "OAuth complete, token: [" + accessToken + "]."); Log.i(TAG, "" +accessToken); Toast.makeText(ActivityWebView.this, "Token: " + accessToken, Toast.LENGTH_SHORT).show(); } } }); webview.loadUrl(url); }
-
SubbaReddy PolamReddy almost 12 yearsi didn't get any idea from this please elaborate this url
-
SubbaReddy PolamReddy almost 12 yearshere USER_ID means either username or client_id...and please give it in a url manner..
-
Sami Eltamawy almost 11 yearsIt works with me. But, what about the accessToken? Can I use one fixed accessToken with my app to let too many user get the images using the same accessToken (Concurrent access with same AccessToken)
-
Sami Eltamawy almost 11 yearsCan I generate one accessToken to use it with multiple users? @SubbaReddyPolamReddy,
-
SubbaReddy PolamReddy almost 11 yearsu have to generate access token from your client id and secret and use that access token in your app
-
Sami Eltamawy almost 11 yearsCan I use this AccessToken hardcoded into my app to make all user can use the app with this access token? Will this make any problem with the big number of users?
-
Daniel Nazareth over 10 years@SubbaReddyPolamReddy This PhotoSet is a class that you've created?
-
John about 10 yearswhat this two lines refers PhotoSet set = new PhotoSet(); and thesets.add(set);
-
SubbaReddy PolamReddy about 9 yearsNothing related with PhotoSet i.e for my local thong i created that class. u can avoid those two lines..