I have very small issue and I think the issue is in lib/[login to view URL] but im not sure.
I'm having several names and access tokens stored in my MySql database and I want to display images for those users.
I have found a library online and it works great. I'm testing my account and so far so good. But the problem appears when I'm display all accounts. It's just showing latest account added.. While loop is working great to fetch data from MySQL but the problem comes when I add this Instagram code. I want to dislay all instagram accounts and their images which I have in the database.
Here is the code: lib/[login to view URL]
<?php
class InstaWCD{
function userID(){
$username = strtolower($this->username); // sanitization
$token = $this->access_token;
$url = "[login to view URL]".$username."&access_token=".$token;
$get = file_get_contents($url);
$json = json_decode($get);
foreach($json->data as $user){
if($user->username == $username){
return $user->id;
}
}
return '00000000'; // return this if nothing is found
}
function userMedia(){
$url = '[login to view URL]'.$this->userID().'/media/recent/?access_token='.$this->access_token;
$content = file_get_contents($url);
return $json = json_decode($content, true);
}
}
$insta = new InstaWCD();
$insta->username = $username;
$insta->access_token = $access_token;
?>
And the code I'm trying to run.
<?php
$statement = $dbConn->prepare("SELECT v2_instagram_users.user_id, v2_instagram_users.instagram_id, [login to view URL], [login to view URL], [login to view URL], v2_instagram_users.instagram_access_token, users.user_name, users.user_age, [login to view URL], [login to view URL], users.gender_search, users.age_from, users.age_to
FROM v2_instagram_users, users
WHERE v2_instagram_users.user_id = [login to view URL]
ORDER by [login to view URL] DESC");
$statement->execute();
while ($row = $statement->fetch(PDO::FETCH_BOTH)) {
$username = $row['username'];
$access_token = $row['instagram_access_token'];
$count = 20; // number of images to show
include 'lib/[login to view URL]'; //include instagram library
?>
<?php
$ins_media = $insta->userMedia();
$i = 0;
foreach ($ins_media['data'] as $vm):
if($count == $i){ break;}
$i++;
$img = $vm['images']['low_resolution']['url'];
$link = $vm["link"];
?>
<a target="_blank" href="<?php echo $link ?>">
<img src="<?php echo $img; ?>" width="175" style="float:left;" />
</a>
<?php endforeach ?>
<?php
}
?>
Can you solve this.. This should take 5 mins max if you are good developer :)