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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18458038/
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-25 17:36:03  来源:igfitidea点击:

How to use instagram api to fetch image with certain hashtag?

phpjavascriptapiinstagram

提问by youaremysunshine

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

我最近正在学习 instagram api 以将某些主题标签图像提取到我的网站中。

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

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

Anyone can help?

任何人都可以帮忙吗?

Thanks!

谢谢!

回答by Ismail Altun?ren

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.

如果您只需要基于标签显示图像,则不需要包含包装类“instagram.class.php”。因为 Instagram API 中的媒体和标签端点不需要身份验证。您可以使用以下基于 curl 的函数根据您的标签检索结果。

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

回答by Bill Rollins

You will need to use the API endpoint for getting a list of recently tagged media by the hashtag. It would look something like this to get media for the hashtag #superpickle

您将需要使用 API 端点来获取由主题标签最近标记的媒体列表。为#superpickle 标签获取媒体看起来像这样

https://api.instagram.com/v1/tags/superpickle/media/recent

You will need to read the Instagram API documentation to learn more about it and how to register for a client ID. http://instagram.com/developer/

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

回答by josecatalani

You can use statigram cURL method, isnt Instagram API, but can resolve it. Im use CodeIgniter and make a service to return a XML, usign simple_xml_load to read feed. Good Lucky.

您可以使用 statigram cURL 方法,不是 Instagram API,但可以解决它。我使用 CodeIgniter 并制作一个服务来返回一个 XML,使用 simple_xml_load 来读取提要。祝你好运。

$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_URL, "http://statigr.am/feed/cristiano");
$content = curl_exec($curl);
curl_close($curl);

$this->xml = simplexml_load_string($content, 'SimpleXMLElement', LIBXML_NOCDATA);

echo json_encode($this->xml->channel);