如何使用instagram api获取具有特定主题标签的图像?

you*_*ine 7 javascript php api instagram

我正在学习instagram api,以便最近在我的网站上获取某些hashtag图像.

在网上搜索很长一段时间后,我找不到任何可行的代码.

有人可以帮忙吗?

谢谢!

Ism*_*ren 12

如果您只需要在标记上显示图像,则不包含包装类"instagram.class.php".由于Instagram API中的媒体和标记端点不需要身份验证.您可以使用以下基于卷曲的函数根据您的标记检索结果.

function callInstagram($url)
{
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => 2
));

$result = curl_exec($ch);
curl_close($ch);
return $result;
}

$tag = 'YOUR_TAG_HERE';
$client_id = "YOUR_CLIENT_ID";

$url = 'https://api.instagram.com/v1/tags/'.$tag.'/media/recent?client_id='.$client_id;

$inst_stream = callInstagram($url);
$results = json_decode($inst_stream, true);

//Now parse through the $results array to display your results... 
foreach($results['data'] as $item){
    $image_link = $item['images']['low_resolution']['url'];
    echo '<img src="'.$image_link.'" />';
}
Run Code Online (Sandbox Code Playgroud)


小智 5

您需要使用API​​端点通过主题标签获取最近标记的媒体列表.看起来像是为了获得#superpickle标签的媒体

https://api.instagram.com/v1/tags/superpickle/media/recent
Run Code Online (Sandbox Code Playgroud)

您需要阅读Instagram API文档以了解有关它的更多信息以及如何注册客户端ID.http://instagram.com/developer/