Php Instagram小部件无效返回
我想用PHP7在我的网站上展示Instagram照片。 我已经注册了我的应用程序,并从Instagram中添加了clientId和secretId。但下面的代码给出了错误:数据是非对象的aof,而foreach是无效的参数Php Instagram小部件无效返回,php,instagram,Php,Instagram,我想用PHP7在我的网站上展示Instagram照片。 我已经注册了我的应用程序,并从Instagram中添加了clientId和secretId。但下面的代码给出了错误:数据是非对象的aof,而foreach是无效的参数 <?php // Supply a user id and an access token $clientid = "my client id"; $accessToken = "my client secret"; // Gets o
<?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
参考此-
如果我是对的,您只有
客户ID
和客户机密
,但您没有访问令牌
跟我走
首先,您必须使用客户端ID和客户端机密创建访问\u令牌
访问以下网站之一,使访问\u令牌
instagram
帐户,让您的访问\u令牌
创建访问令牌后,其格式如下:
XXXXXXXXX.XXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
然后,在控制器函数中添加以下代码
$access_token = 'xxxxxxxxxx.xxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; // your access_token will be this format
$count_feed = 2; // how many feed want to load
$requestURL = 'https://api.instagram.com/v1/users/self/media/recent?access_token='.$access_token.'&count='.$count_feed;
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $requestURL,
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => 1
));
$json_response = curl_exec($ch);
curl_close($ch);
$insta_feeds = json_decode($json_response, true);
_e($insta_feeds); // $insta_feeds['data'] will return feed
您可以使用Instagram库获取提要。请在此处查看库:var dump$result。是什么?ValDUP返回NulLu你应该考虑使用这个包吗?所以请求失败了。看看curl_error()给了你什么,curl error给了我什么,对于你自己的访问令牌,它工作得非常好,你能详细说明一下吗,到底什么对你不起作用?