php 如何使用 Instagram API 获取图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40105795/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:06:51  来源:igfitidea点击:

How to get images using Instagram API

phpinstagram-api

提问by adeel ali

How to get users images from Instagram API?

如何从Instagram API获取用户图片?

access_token=4049241557.1677ed0.5324ad17d9314645b528ad112da8d56e

access_token=4049241557.1677ed0.5324ad17d9314645b528ad112da8d56e

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

但没有成功,它只给我用户信息。如何使用 Instagram API 获取图像?

回答by krisrak

Use this API:

使用这个 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_tokenyou have posted, that user does not have any photos posted, so it will return empty array)

这将获取您的照片,(但从access_token您发布的内容来看,该用户没有发布任何照片,因此它将返回空数组)

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_contentscope and if you are in sandbox mode, only sandbox users can be accessed until your app is reviewed and live

您应该已通过public_content范围进行身份验证,如果您处于沙箱模式,则只有沙箱用户才能访问您的应用程序,直到您的应用程序被审核并上线

回答by Williaan Lopes

You could use this library Cosenary.

你可以使用这个库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.

希望这可以帮助。