Advertisement
Guest User

Untitled

a guest
Jan 27th, 2016
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. <?php
  2. class InstaWCD{
  3.  
  4.  
  5. function userID(){
  6. $username = strtolower($this->username); // sanitization
  7. $token = $this->access_token;
  8. $url = "https://api.instagram.com/v1/users/search?q=".$username."&access_token=".$token;
  9. $get = file_get_contents($url);
  10. $json = json_decode($get);
  11.  
  12. foreach($json->data as $user){
  13. if($user->username == $username){
  14. return $user->id;
  15. }
  16. }
  17.  
  18. return '00000000'; // return this if nothing is found
  19. }
  20.  
  21. function userMedia(){
  22. $url = 'https://api.instagram.com/v1/users/'.$this->userID().'/media/recent/?access_token='.$this->access_token;
  23.  
  24. $content = file_get_contents($url);
  25. return $json = json_decode($content, true);
  26. }
  27.  
  28. }
  29. $insta = new InstaWCD();
  30. $insta->username = $username;
  31. $insta->access_token = $access_token;
  32. ?>
  33.  
  34. <?php
  35.  
  36.  
  37.  
  38. $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
  39. FROM v2_instagram_users, users
  40. WHERE v2_instagram_users.user_id = users.id
  41. ORDER by v2_instagram_users.id DESC");
  42. $statement->execute();
  43.  
  44. while ($row = $statement->fetch(PDO::FETCH_BOTH)) {
  45.  
  46. $username = $row['username'];
  47. $access_token = $row['instagram_access_token'];
  48.  
  49. $count = 20; // number of images to show
  50. include 'lib/instagram_single.php'; //include instagram library
  51.  
  52.  
  53. ?>
  54.  
  55. <?php
  56. $ins_media = $insta->userMedia();
  57. $i = 0;
  58. foreach ($ins_media['data'] as $vm):
  59. if($count == $i){ break;}
  60. $i++;
  61. $img = $vm['images']['low_resolution']['url'];
  62. $link = $vm["link"];
  63. ?>
  64.  
  65. <a target="_blank" href="<?php echo $link ?>">
  66. <img src="<?php echo $img; ?>" width="175" style="float:left;" />
  67. </a>
  68. <?php endforeach ?>
  69.  
  70. <?php
  71. }
  72. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement