如何获取用户的Instagram feed [英] How to get a user's Instagram feed
问题描述
我想使用PHP获取用户的Instagram提要.我已经注册了一个Instagram开发者帐户,并尝试提取用户的信息和照片,但是响应不稳定.有时,我会收到响应,而其他时候,我仍然会收到错误消息:access_token丢失.是否有通过用户名获取用户照片供稿的可靠示例?
I'd like to get a user's Instagram feed using PHP. I've signed up for an Instagram Developer Account and tried pulling in a user's info and photos, but the response isn't stable. Sometimes I get a response and other times I keep getting the error: access_token is missing. Is there a solid example of getting a user's feed of photos by username?
理想情况下,我希望它像这样简单:
Ideally, I'd like it to be as simple as:
$instagram = new Instagram();
$photos = $instagram->getPhotos("username-goes-here");
Instagram是处理所有请求的类.任何帮助或指示,不胜感激.谢谢!
Where Instagram is a class that handles all the requests. Any help or direction is appreciated. Thanks!
推荐答案
尝试一下,
<?php
function fetchData($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
$result = fetchData("https://api.instagram.com/v1/users/ID-GOES-HERE/media/recent/?access_token=TOKEN-GOES-HERE");
$result = json_decode($result);
foreach ($result->data as $post) {
// Do something with this data.
}
?>
这对您有帮助吗?
这篇关于如何获取用户的Instagram feed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!