我在获取我的Instagram列表时遇到问题。请参阅下面的代码。我做错了什么?
我一直收到这个错误: 警告:在第51行的C:\ wamp \ www \ art \ index.php中为foreach()提供的参数无效
function connectToInstagram($url){
$ch = curl_init(); //curl handle
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => 2));
$result = curl_exec($ch);
curl_close($ch);
}
function printFriends($access_token){
$url = 'https://api.instagram.com/v1/users/self/follows?access_token='.$access_token;
$instagramInfo = connectToInstagram($url);
$results = json_decode($instagramInfo, true);
//Parse through the information one by one.
foreach($results['data'] as $items){
$userImageURL = $items['profile_picture'];
echo '<img src="'.$userImageURL.'"/><br />';
}
}
答案 0 :(得分:1)
您的函数connectToInstagram()
不会返回任何数据......
在右括号之前需要return $result;
。