How to get images using Instagram API

末鹿安然 提交于 2019-12-11 02:11:31

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/40105795/how-to-get-images-using-instagram-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!