From 1e001065b5c5446086aad632a7ec00f60f87d201 Mon Sep 17 00:00:00 2001 From: Artyom Yagovdik Date: Thu, 16 Jun 2016 15:59:49 +0600 Subject: [PATCH 1/8] Added: getting comments by media --- src/Instagram.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Instagram.php b/src/Instagram.php index 6a90a41..844ac77 100644 --- a/src/Instagram.php +++ b/src/Instagram.php @@ -68,6 +68,21 @@ public static function getMediaAfterByUserID($user = null, $min_id, $count = 16, return $media; } + + public static function getCommentsByMediaShortcode($media_shortcode = null, $count = 16, $assoc = false) + { + + $comments = "comments.last($count) { count, nodes { id, created_at, text, user { id, profile_pic_url, username } }, page_info }"; + + $parameters = urlencode("ig_shortcode({$media_shortcode}) { $comments }"); + $url = "https://www.instagram.com/query/?q=$parameters&ref=media%3A%3Ashow"; + $comments = json_decode(file_get_contents($url),($assoc || $assoc == "array")); + if($assoc == "array") + $comments = $comments["comments"]["nodes"]; + else + $comments = $comments->comments->nodes; + return $comments; + } } From 0f237cddbb6c414e11270cf8f3bbf4344919c16c Mon Sep 17 00:00:00 2001 From: Artyom Yagovdik Date: Thu, 16 Jun 2016 16:29:15 +0600 Subject: [PATCH 2/8] Added: method for paginate comments on the photo page --- src/Instagram.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Instagram.php b/src/Instagram.php index 844ac77..9453baf 100644 --- a/src/Instagram.php +++ b/src/Instagram.php @@ -74,6 +74,21 @@ public static function getCommentsByMediaShortcode($media_shortcode = null, $cou $comments = "comments.last($count) { count, nodes { id, created_at, text, user { id, profile_pic_url, username } }, page_info }"; + $parameters = urlencode("ig_shortcode({$media_shortcode}) { $comments }"); + $url = "https://www.instagram.com/query/?q=$parameters&ref=media%3A%3Ashow"; + $comments = json_decode(file_get_contents($url),($assoc || $assoc == "array")); + if($assoc == "array") + $comments = $comments["comments"]["nodes"]; + else + $comments = $comments->comments->nodes; + return $comments; + } + + public static function getCommentsBeforeByMediaShortcode($media_shortcode = null, $max_id, $count = 16, $assoc = false) + { + + $comments = "comments.before($max_id, $count) { count, nodes { id, created_at, text, user { id, profile_pic_url, username } }, page_info }"; + $parameters = urlencode("ig_shortcode({$media_shortcode}) { $comments }"); $url = "https://www.instagram.com/query/?q=$parameters&ref=media%3A%3Ashow"; $comments = json_decode(file_get_contents($url),($assoc || $assoc == "array")); From bd38a6acfe94ffdb1da542f20bb14e1eabc04500 Mon Sep 17 00:00:00 2001 From: Artyom Yagovdik Date: Thu, 16 Jun 2016 16:29:28 +0600 Subject: [PATCH 3/8] Added: tests for comments --- test/example.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/example.php b/test/example.php index ef26613..08bcee4 100644 --- a/test/example.php +++ b/test/example.php @@ -10,6 +10,12 @@ //Get 10 images/videos after the media with the id 1060728019300790746 from Selena Gomex $media = Bolandish\Instagram::getMediaAfterByUserID(460563723,1060728019300790746, 10); +//Its getting 10 last comments under Selena Gomezs photo +$media = Bolandish\Instagram::getCommentsByMediaShortcode("BGQh8XmOjLM", 10); + +//Get 10 comments before the comment with the id 17862588298017953 under Selena Gomezs photo +$media = Bolandish\Instagram::getCommentsBeforeByMediaShortcode("BGQh8XmOjLM", 17862588298017953, 10); + //Display square images only $media = Bolandish\Instagram::getMediaByHashtag("wildlife", 20); foreach($media as $value){ From 914ff14d85c1aaeffe8ed96482dd0ad577806015 Mon Sep 17 00:00:00 2001 From: Artyom Yagovdik Date: Thu, 16 Jun 2016 16:29:56 +0600 Subject: [PATCH 4/8] Removed: php close tag --- src/Instagram.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Instagram.php b/src/Instagram.php index 9453baf..2c77a8f 100644 --- a/src/Instagram.php +++ b/src/Instagram.php @@ -98,9 +98,4 @@ public static function getCommentsBeforeByMediaShortcode($media_shortcode = null $comments = $comments->comments->nodes; return $comments; } -} - - - -?> - +} \ No newline at end of file From 103ee82a90e0ae3ee214d210a9a61e6be131874f Mon Sep 17 00:00:00 2001 From: Peter Bakonyi-Karpati Date: Fri, 28 Oct 2016 14:20:19 +0200 Subject: [PATCH 5/8] Using cURL instead of file_get_contents when the PHP cURL library is available --- src/Instagram.php | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/Instagram.php b/src/Instagram.php index 2c77a8f..8dc8285 100644 --- a/src/Instagram.php +++ b/src/Instagram.php @@ -2,6 +2,20 @@ namespace Bolandish; class Instagram { + + protected static function getContentsFromUrl($url) { + if (!function_exists('curl_init')) { + return file_get_contents($url); + } + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + $output = curl_exec($ch); + curl_close($ch); + return $output; + } + public static function getMediaByHashtag($hashtag = null, $count = 16, $assoc = false, $comment_count = false) { if ( empty($hashtag) || !is_string($hashtag) ) @@ -16,7 +30,7 @@ public static function getMediaByHashtag($hashtag = null, $count = 16, $assoc = $hashtag = strtolower($hashtag); $parameters = urlencode("ig_hashtag($hashtag) { media.first($count) { count, nodes { caption, code, $comments, date, dimensions { height, width }, display_src, id, is_video, likes { count }, owner { id, username, full_name, profile_pic_url, biography }, thumbnail_src, video_views, video_url }, page_info } }"); $url = "https://www.instagram.com/query/?q=$parameters&ref=tags%3A%3Ashow"; - $media = json_decode(file_get_contents($url), ($assoc || $assoc == "array")); + $media = json_decode(static::getContentsFromUrl($url), ($assoc || $assoc == "array")); if($assoc == "array") $media = $media["media"]["nodes"]; else @@ -37,7 +51,7 @@ public static function getMediaByUserID($user = null, $count = 16, $assoc = fals } $parameters = urlencode("ig_user($user) { media.first($count) { count, nodes { caption, code, $comments, date, dimensions { height, width }, display_src, id, is_video, likes { count }, owner { id, username, full_name, profile_pic_url, biography }, thumbnail_src, video_views, video_url }, page_info } }"); $url = "https://www.instagram.com/query/?q=$parameters&ref=tags%3A%3Ashow"; - $media = json_decode(file_get_contents($url),($assoc || $assoc == "array")); + $media = json_decode(static::getContentsFromUrl($url),($assoc || $assoc == "array")); if($assoc == "array") $media = $media["media"]["nodes"]; else @@ -60,7 +74,7 @@ public static function getMediaAfterByUserID($user = null, $min_id, $count = 16, $parameters = urlencode("ig_user($user) { media.after($min_id,$count) { count, nodes { caption, code, $comments, date, dimensions { height, width }, display_src, id, is_video, likes { count }, owner { id, username, full_name, profile_pic_url, biography }, thumbnail_src, video_views, video_url }, page_info } }"); $url = "https://www.instagram.com/query/?q=$parameters&ref=tags%3A%3Ashow"; - $media = json_decode(file_get_contents($url),($assoc || $assoc == "array")); + $media = json_decode(static::getContentsFromUrl($url),($assoc || $assoc == "array")); if($assoc == "array") $media = $media["media"]["nodes"]; else @@ -76,7 +90,7 @@ public static function getCommentsByMediaShortcode($media_shortcode = null, $cou $parameters = urlencode("ig_shortcode({$media_shortcode}) { $comments }"); $url = "https://www.instagram.com/query/?q=$parameters&ref=media%3A%3Ashow"; - $comments = json_decode(file_get_contents($url),($assoc || $assoc == "array")); + $comments = json_decode(static::getContentsFromUrl($url),($assoc || $assoc == "array")); if($assoc == "array") $comments = $comments["comments"]["nodes"]; else @@ -91,7 +105,7 @@ public static function getCommentsBeforeByMediaShortcode($media_shortcode = null $parameters = urlencode("ig_shortcode({$media_shortcode}) { $comments }"); $url = "https://www.instagram.com/query/?q=$parameters&ref=media%3A%3Ashow"; - $comments = json_decode(file_get_contents($url),($assoc || $assoc == "array")); + $comments = json_decode(static::getContentsFromUrl($url),($assoc || $assoc == "array")); if($assoc == "array") $comments = $comments["comments"]["nodes"]; else From 150b8e99486b078e4d8d6fb9b28640002af8dd72 Mon Sep 17 00:00:00 2001 From: Thomas Bolander Date: Thu, 24 Nov 2016 14:42:33 +0100 Subject: [PATCH 6/8] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 1fff025..8b3c89b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +24-11-2016 : Instagram closed the endpoint. We are trying figure out the new endpoint + # Get instagram images by hashtag and user id! A workaround for the new Instagram policy to get images by hashtag and user id. No need for accesstoken :) From be39a9ee1b6908ef479ee7fc8c1d746a0221f445 Mon Sep 17 00:00:00 2001 From: Thomas Bolander Date: Thu, 24 Nov 2016 14:44:34 +0100 Subject: [PATCH 7/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8b3c89b..5d57cb2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -24-11-2016 : Instagram closed the endpoint. We are trying figure out the new endpoint +11/24/2016 : Instagram closed the endpoint. We are trying figure out a new way to get access to it. # Get instagram images by hashtag and user id! A workaround for the new Instagram policy to get images by hashtag and user id. From 31275ddc250de19d7b6ff85091e2f84c9e8ccf82 Mon Sep 17 00:00:00 2001 From: Thomas Bolander Date: Thu, 24 Nov 2016 14:45:56 +0100 Subject: [PATCH 8/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5d57cb2..f6eff0c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -11/24/2016 : Instagram closed the endpoint. We are trying figure out a new way to get access to it. +24-11-2016 : Instagram closed the endpoint. We are trying figure out a new way to get access to it. # Get instagram images by hashtag and user id! A workaround for the new Instagram policy to get images by hashtag and user id.