UPDATE: Ok, so apparently instagram changed its API that’s why it’s not working. I have no idea what to do now.
I have a php code that calls instagram api and it has been working perfectly so far. However, it stopped working today – it gives an invalid argument error as you can see below (on the left).
http://www.weheartalacati.com/alavya-hotel/
The error is: Warning: Invalid argument supplied for foreach() in /home/alacati/public_html/wp-content/themes/coastline/content.php on line 303
The code below is the related part of the code (around line 303 and before), do you know what could be the problem? Any help would be greatly appreciated. (the problematic line is the one that starts with ” foreach ($result->data as $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>