加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 18:24:20 所属栏目:PHP教程 来源:网络整理
导读:我正在学习instagram api,最近在我的网站上获取了某些hashtag图像. 在网上搜索了很长时间后,我找不到任何可行的代码. 有人可以帮忙吗? 谢谢! 如果您只需要在标记上显示图像,则不包含包装类“instagram.class.php”.作为媒体 Instagram API中的标记端点不需
我正在学习instagram api,最近在我的网站上获取了某些hashtag图像.

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

有人可以帮忙吗?

谢谢!

如果您只需要在标记上显示图像,则不包含包装类“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.'" />';
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读