php - Show several Instagram accounts (10 images/account) on one 1 page -
i'm having several names , access tokens stored in mysql database , want display images users.
i have found library online , works great. i'm testing account , far good. problem appears when i'm display accounts. it's showing latest account added.. while loop working great fetch data mysql problem comes when add instagram code.
here code: lib/instagram_single.php
<?php class instawcd{ function userid(){ $username = strtolower($this->username); // sanitization $token = $this->access_token; $url = "https://api.instagram.com/v1/users/search?q=".$username."&access_token=".$token; $get = file_get_contents($url); $json = json_decode($get); foreach($json->data $user){ if($user->username == $username){ return $user->id; } } return '00000000'; // return if nothing found } function usermedia(){ $url = 'https://api.instagram.com/v1/users/'.$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 code i'm trying run.
<?php $statement = $dbconn->prepare("select v2_instagram_users.user_id, v2_instagram_users.instagram_id, v2_instagram_users.username, v2_instagram_users.name, v2_instagram_users.bio, v2_instagram_users.instagram_access_token, users.user_name, users.user_age, users.country, users.gender, users.gender_search, users.age_from, users.age_to v2_instagram_users, users v2_instagram_users.user_id = users.id order v2_instagram_users.id desc"); $statement->execute(); while ($row = $statement->fetch(pdo::fetch_both)) { $username = $row['username']; $access_token = $row['instagram_access_token']; $count = 20; // number of images show include 'lib/instagram_single.php'; //include instagram library ?> <?php $ins_media = $insta->usermedia(); $i = 0; foreach ($ins_media['data'] $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 } ?>
anyone has ideas why 1 account being displayed , images when have 4 acccounts in database?
cheerz :)
Comments
Post a Comment