Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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 as $user){
- if($user->username == $username){
- return $user->id;
- }
- }
- return '00000000'; // return this if nothing is 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;
- ?>
- <?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
- FROM v2_instagram_users, users
- WHERE v2_instagram_users.user_id = users.id
- ORDER by 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 to show
- include 'lib/instagram_single.php'; //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
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement