如何使用Instagram的API与特定主题标签获取图像? [英] How to use instagram api to fetch image with certain hashtag?

查看:372
本文介绍了如何使用Instagram的API与特定主题标签获取图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学习了Instagram的API来获取最近一定包括hashtag图像到我的网站。

I am learning the instagram api to fetch certain hashtag image into my website recently.

在网寻找了很长时间后,我coundnt找到任何可行的code吧。

After searching on the webs for a very long time I coundnt find any workable code for it.

任何人都可以帮忙吗?

谢谢!

推荐答案

如果你只需要在标签上显示图像的基础上,再有就是不包括包装类instagram.class.php。随着媒体和放大器; Instagram的API中的标签端点不要求身份验证。您可以使用下面的卷曲基于函数根据您的标签检索结果。

If you only need to display the images base on a tag, then there is not to include the wrapper class "instagram.class.php". As the Media & Tag Endpoints in Instagram API do not require authentication. You can use the following curl based function to retrieve results based on your tag.

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.'" />';
}

这篇关于如何使用Instagram的API与特定主题标签获取图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆