我想使用 PHP7 在我的网站上显示 Instagram 照片。 我已经注册了我的应用程序,并从 Instagram 添加了 clientId 和 secretId。但是下面的代码给了我错误:数据是非对象并且 foreach 是无效的论点。
<?php
// Supply a user id and an access token
$clientid = "my client id";
$accessToken = "my client secret";
// 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/{$clientid}/media/recent/?access_token={$accessToken}");
$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 ?>
最佳答案
您只能为自己使用此 api,不能为任何其他用户使用。
https://api.instagram.com/v1/users/self/media/recent/?access_token=ACCESS-TOKEN
关于php - Instagram 小部件无效返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49983702/