5

How to get users images from Instagram API?

access_token=4049241557.1677ed0.5324ad17d9314645b528ad112da8d56e

But no success, it's giving me only user info. How can I get images using Instagram API?

Stacked
  • 6,892
  • 7
  • 57
  • 73
adeel ali
  • 59
  • 1
  • 1
  • 4

2 Answers2

8

Use this API:

https://api.instagram.com/v1/users/self/media/recent?access_token={access-token}

This will get your photos,(but it looks like from the access_token you have posted, that user does not have any photos posted, so it will return empty array)

Use this to get other user's photo:

https://api.instagram.com/v1/users/{user-id}/media/recent?access_token={access-token}

you should have authenticated with public_content scope and if you are in sandbox mode, only sandbox users can be accessed until your app is reviewed and live

krisrak
  • 12,882
  • 3
  • 32
  • 46
  • Hi @krisrak how to approve public_content and relationship permission. I submitted my app but they declined both permission. – Abhishek Oct 20 '16 at 18:51
  • what does your app do? – krisrak Oct 21 '16 at 04:19
  • Publishers create a gate and add track to download for other users, he also add a instagram username to follow. If a user wants to download that track then he must follow that instagram user. I'm using PHP api for it. – Abhishek Oct 21 '16 at 12:38
  • i dont think it is a valid usecase and does not comply with the API policy: `A.18. Don't participate in any "like", "share", "comment" or "follower" exchange programs.` https://www.instagram.com/about/legal/terms/api/ – krisrak Oct 21 '16 at 20:06
  • Okay They provide an api to follow users if its not legal then whats the use of that api. I tested in sandbox its working for sandbox users. – Abhishek Oct 22 '16 at 03:04
  • u can like for a business use case, not for `exchange program` – krisrak Oct 22 '16 at 03:32
  • yes its a business, we wants to promote our business using this api – Abhishek Oct 22 '16 at 05:05
  • The remaining Instagram Legacy API permission ("Basic Permission") was disabled on June 29, 2020. As of June 29, third-party apps no longer have access to the Legacy API. To avoid disruption of service to your app and business, developers previously using the Legacy API should instead rely on Instagram Basic Display API and Instagram Graph API. Please request approval for required permissions through the App Review process. https://developers.facebook.com/docs/instagram-basic-display-api – Londeren Jun 30 '20 at 04:46
0

You could use this library Cosenary.

use MetzWeb\Instagram\Instagram;

$instagram = new Instagram(array(
    'apiKey'      => 'YOUR_APP_KEY',
    'apiSecret'   => 'YOUR_APP_SECRET',
    'apiCallback' => 'YOUR_APP_CALLBACK'
));

// grab OAuth callback code
$code = $_GET['code']; 
// or maybe $code = $request->code; // if you are using Laravel
$data = $instagram->getOAuthToken($code);

// set user access token
$instagram->setAccessToken($data);

// and
$pictures = $instagram->getUserMedia();

Read the documentation for more information.

Hope this helps.

Williaan Lopes
  • 1,177
  • 15
  • 11