我将这种结构用于 Instagram:
<?php
// Supply a user id and an access token
$userid = "--user--";
$accessToken = "--token--";
// Gets our data
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;
}
// Pulls and parses data.
$result = fetchData("https://api.instagram.com/v1/users/--user--/media/recent/?access_token=--token--");
$result = json_decode($result);
?>
<?php foreach ($result->data as $post): ?>
<!-- Renders images. @Options (thumbnail,low_resoulution, high_resolution) -->
<a class="group" rel="group1" href="<?= $post->images->standard_resolution->url ?>"><img src="<?= $post->images->thumbnail->url ?>"></a>
<?php endforeach ?>
但是这个打印:
警告:在第 40 行的 /home/mysite/index.php 中为 foreach() 提供了无效参数
40.行:
<?php foreach ($result->data as $post): ?>
这个结构有什么问题?
这个结构是http://www.blueprintinteractive.com/blog/how-instagram-api-fancybox-simplified