更新:好的,显然Instagram改变了它的API,这就是为什么它不起作用。我不知道现在该做什么。
我有一个调用instagram api的PHP代码,到目前为止它一直运行良好。但是,它今天停止工作 - 它会给出一个无效的参数错误,如下所示(左侧)。
http://www.weheartalacati.com/alavya-hotel/
错误是:警告:在第303行的/home/alacati/public_html/wp-content/themes/coastline/content.php中为foreach()提供的参数无效
下面的代码是代码的相关部分(在第303行和之前),你知道可能是什么问题吗?任何帮助将不胜感激。 (有问题的行是以“foreach($ result->数据为$ fotos)”开头的那个行))
<article id="entry-<?php the_ID(); ?>" <?php post_class('entry'); ?>>
<div class="row">
<div class="col-md-4">
<div class="entry-info-wrap">
<?php
$instagramid = get_post_meta($post->ID, 'Instagram', true);
$foursquareid = get_post_meta($post->ID, 'Foursquare', true);
// Supply a user id and an access token
$userid = "xx";
$accessToken = "xx";
// 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, 30);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
// Pulls and parses data.
$result = fetchData("https://api.instagram.com/v1/users/$instagramid/media/recent/?access_token={$accessToken}&count=6");
$result = json_decode($result);
$sonuc = fetchData("https://api.instagram.com/v1/users/$instagramid/?access_token={$accessToken}");
$sonuc = json_decode($sonuc);
$username=$sonuc->data->username;
$profilepic=$sonuc->data->profile_picture;
$sayi=$sonuc->data->counts->media;
$takipci=$sonuc->data->counts->followed_by;
$takipediyor=$sonuc->data->counts->follows;
....
<?php
if ( $instagramid )
{
echo "<br><br>
<span style=\"float:left; -webkit-border-radius: 3px; border-radius: 3px; font-size: 14px; float: left; line-height: 32px; margin-right: 5px; margin-top:12px; padding: 0px 3px 0px 5px; \">
<a target=\"_blank\" href=\"http://instagram.com/".$username."\"><img width=\"80\" border=\"1px\" src=\"".$profilepic."\"></a></span>
<br>
<div style=\"margin-left: 50px;\">
<div style=\"position: relative; float: left; left: 0.00%; width: 75.00%; background-color: #f4f4f4\">
<span style=\"font-weight: bold;font-style: normal;font-size: 12px; letter-spacing: 0px; padding: 0px 0px 0px 0px; \">
<a style=\"color: #3f729b; font-weight: bold; \" target=\"_blank\" href=\"http://instagram.com/".$username."\">".$username."</a> @ instagram</span>
</div>
<div style=\"position: relative; float: left; left: 0.00%; width: 82.00%;\">
<div style=\"position: relative; float: left; left: 0.50%; width: 33.00%;\">
<span style=\"font-weight: lighter; font-style: normal; font-size: 11px; letter-spacing: 0px; padding: 0px 0px 0px 0px; \">Photos<br>
<span style=\"font-weight: bold; \"><span style=\"letter-spacing: 0px;\">".$sayi."</span></span></span>
</div>
<div style=\"position: relative;float: left;left: 1.50%;width: 33.00%;\">
<span style=\"font-weight: lighter;font-style: normal;font-size: 11px; letter-spacing: 0px; padding: 0px 0px 0px 0px; \">Followers<br>
<span style=\"font-weight: bold;\"><span style=\"letter-spacing: 0px;\">".$takipci."</span></span></b></span>
</div>
<div style=\"position: relative; float: right; right: 0.50%; width: 31.00%;\">
<span style=\"font-weight: lighter; font-style: normal; font-size: 11px; letter-spacing: 0px; padding: 0px 0px 0px 0px; \">Following<br>
<span style=\"font-weight: bold;\">
<span style=\"letter-spacing: 0px;\">".$takipediyor."</span></span></span>
</div>
</div>
</div>
<br><br>";
foreach ($result->data as $fotos)
{
$instagramlink = $fotos->link;
$instagramthumb = $fotos->images->thumbnail->url;
$instagramlikes = $fotos->likes->count;
echo "<!-- Renders images. @Options (thumbnail,low_resoulution, high_resolution) -->
<span style=\"font-size: 12px; float:left; margin:5px 0 2px 10px;\">
<a target=\"_blank\" class=\"group\" rel=\"group1\" href=\"".$instagramlink."\">
<img width=\"90\" src=\"".$instagramthumb."\">
</a>
<span style=\"font-weight:bold; float:left;\"></span>
<span style=\"float:right;\"><span style=\"color:red; font-weight: bolder;\">❤ </span>".$instagramlikes."</span>
</span>";
}
} else { echo ""; }
?>
</div>
</div>
<div class="col-md-8">
<?php ci_post_thumbnail(); ?>
<div class="entry-content">
<?php the_content(); ?>
</div>
<?php if ( is_single() ) {
comments_template();
} ?>
</div>
</div>
</article>