Php 显示Instagram图像
如何在我的网站上显示instagram照片? 我试图使用Instagram的API解决这个问题,但它不能正常工作:Php 显示Instagram图像,php,instagram,photo,display,Php,Instagram,Photo,Display,如何在我的网站上显示instagram照片? 我试图使用Instagram的API解决这个问题,但它不能正常工作: $user = file_get_contents( "https://api.instagram.com/v1/users/self/media/recent/?access_token=$access_token" ); $user = json_decode($user, true)['data']; $media = file_get_contents( "https:/
$user = file_get_contents( "https://api.instagram.com/v1/users/self/media/recent/?access_token=$access_token" );
$user = json_decode($user, true)['data'];
$media = file_get_contents( "https://api.instagram.com/v1/users/self/media/recent/?access_token=$access_token&count=5" );
$media = json_decode($media, true)['data'];
print_r($media);
我从回复中看到,您希望在打印
$media
后看到图像,这是一个数组
例如,如果您想单独访问Instgram配置文件中的图像,您应该循环访问从API获取的数据,分别检索每个图像,并轻松访问数组中的URL索引,进入图像->低分辨率->URL。“”alt=“”.$post->caption->text。“”width=“100%”height=“auto”/>
';
}
}
这是什么意思-不正确?打印($media)
向您展示了什么?什么不起作用?是否有任何错误消息,如果有,请将其发布在此处。您是在尝试嵌入某人的整个提要还是仅嵌入一些选定的图片?它只打印文本信息,而不打印图像,我正在尝试嵌入最后5张图片这是我尝试遵循的教程:@AlessandraLuz Glay帮助
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/self/media/recent/?access_token=$access_token");
$result = json_decode($result);
foreach ($result->data as $post) {
if(empty($post->caption->text)) {
// Do Nothing
}
else {
echo '
<img src="'.$post->images->low_resolution->url.'" alt="'.$post->caption->text.'" width="100%" height="auto" />
';
}
}