Android: how to get custom photos on Instagram?

In my application, my requirement is to get user photos and show in my application.

To do this, I authenticate, received an access token and enter the user password, but this shows that you do not have permission to open this page. Next, how can I get a user profile and photos.

here is my code:

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); } 
+4
source share
2 answers

try this code, i got a 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(); } } 
+9
source

GET /users/[USER_ID]/media/recent/?access_token=[ACCESS_TOKEN]

You can click this URL to get the user feed (last 20 photos). This will give you a JSON array that you will need to parse and display in your application.

+2
source

Source: https://habr.com/ru/post/1435182/


All Articles