From 16e4ea9d50a825faa1e2d36682ce1c549ae69473 Mon Sep 17 00:00:00 2001 From: raiym Date: Wed, 24 Jan 2018 18:45:12 +0300 Subject: [PATCH 1/6] Add account followings example --- examples/getAccountFollowings.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 examples/getAccountFollowings.php diff --git a/examples/getAccountFollowings.php b/examples/getAccountFollowings.php new file mode 100644 index 00000000..80adb6a2 --- /dev/null +++ b/examples/getAccountFollowings.php @@ -0,0 +1,13 @@ +login(); +sleep(2); // Delay to mimic user + +$username = 'kevin'; +$followers = []; +$account = $instagram->getAccount($username); +sleep(1); +$followers = $instagram->getFollowing($account->getId(), 1000, 100, true); // Get 1000 followings of 'kevin', 100 a time with random delay between requests +echo '
' . json_encode($followers, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . '
'; \ No newline at end of file From dd79e78862a4faec461148e75ed278764a28fecd Mon Sep 17 00:00:00 2001 From: Fabiano Roberto Date: Fri, 26 Jan 2018 09:55:09 +0100 Subject: [PATCH 2/6] Handle 'profile_pic_url_hd' --- src/InstagramScraper/Model/Account.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/InstagramScraper/Model/Account.php b/src/InstagramScraper/Model/Account.php index 884925a5..3c3bb45f 100644 --- a/src/InstagramScraper/Model/Account.php +++ b/src/InstagramScraper/Model/Account.php @@ -32,6 +32,12 @@ class Account extends AbstractModel */ protected $profilePicUrl = ''; + /** + * Profile picture url HD + * @var string + */ + protected $profilePicUrlHd = ''; + /** * Information filled by user * @var string @@ -123,6 +129,20 @@ public function getProfilePicUrl() return $this->profilePicUrl; } + /** + * @return string + */ + public function getProfilePicUrlHd() + { + $toReturn = $this->profilePicUrl; + + if ($this->profilePicUrlHd !== '') { + $toReturn = $this->profilePicUrlHd; + } + + return $toReturn; + } + /** * @return string */ @@ -199,6 +219,9 @@ protected function initPropertiesCustom($value, $prop, $array) case 'profile_pic_url': $this->profilePicUrl = $value; break; + case 'profile_pic_url_hd': + $this->profilePicUrlHd = $value; + break; case 'biography': $this->biography = $value; break; From b98134e6f810b3f7dc38e1303232465c69aa99fb Mon Sep 17 00:00:00 2001 From: Mark Tertishniy Date: Fri, 2 Feb 2018 15:35:04 +1000 Subject: [PATCH 3/6] Add sidecar images for 'sidecar' media type. Fixes #221 --- examples/getSidecarMediaByUrl.php | 39 ++++++++++++++++++++++++++++ src/InstagramScraper/Model/Media.php | 26 +++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 examples/getSidecarMediaByUrl.php diff --git a/examples/getSidecarMediaByUrl.php b/examples/getSidecarMediaByUrl.php new file mode 100644 index 00000000..45318360 --- /dev/null +++ b/examples/getSidecarMediaByUrl.php @@ -0,0 +1,39 @@ +getId()}\n"; + echo "${padding}Shotrcode: {$media->getShortCode()}\n"; + echo "${padding}Created at: {$media->getCreatedTime()}\n"; + echo "${padding}Caption: {$media->getCaption()}\n"; + echo "${padding}Number of comments: {$media->getCommentsCount()}\n"; + echo "${padding}Number of likes: {$media->getLikesCount()}\n"; + echo "${padding}Get link: {$media->getLink()}\n"; + echo "${padding}High resolution image: {$media->getImageHighResolutionUrl()}\n"; + echo "${padding}Media type (video/image/sidecar): {$media->getType()}\n"; +} + +// If account is public you can query Instagram without auth +$instagram = new \InstagramScraper\Instagram(); + +// If account is private and you subscribed to it firstly login +$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', '/path/to/cache/folder'); +$instagram->login(); + +$media = $instagram->getMediaByUrl('https://www.instagram.com/p/BQ0lhTeAYo5'); +echo "Media info:\n"; +printMediaInfo($media); + +$padding = ' '; +echo "Sidecar medias info:\n"; +foreach ($media->getSidecarMedias() as $sidecarMedia) { + printMediaInfo($sidecarMedia, $padding); + echo "\n"; +} + +$account = $media->getOwner(); +echo "Account info:\n"; +echo "Id: {$account->getId()}\n"; +echo "Username: {$account->getUsername()}\n"; +echo "Full name: {$account->getFullName()}\n"; +echo "Profile pic url: {$account->getProfilePicUrl()}\n"; diff --git a/src/InstagramScraper/Model/Media.php b/src/InstagramScraper/Model/Media.php index 136b556a..79506d4a 100644 --- a/src/InstagramScraper/Model/Media.php +++ b/src/InstagramScraper/Model/Media.php @@ -135,6 +135,11 @@ class Media extends AbstractModel */ protected $commentsCount = 0; + /** + * @var Media[]|array + */ + protected $sidecarMedias = []; + /** * @param string $code * @@ -366,6 +371,14 @@ public function getCommentsCount() return $this->commentsCount; } + /** + * @return Media[]|array + */ + public function getSidecarMedias() + { + return $this->sidecarMedias; + } + /** * @param $value * @param $prop @@ -495,6 +508,19 @@ protected function initPropertiesCustom($value, $prop, $arr) } } break; + case 'edge_sidecar_to_children': + if (!is_array($arr[$prop]['edges'])) { + break; + } + + foreach ($arr[$prop]['edges'] as $edge) { + if (!isset($edge['node'])) { + continue; + } + + $this->sidecarMedias[] = static::create($edge['node']); + } + break; case 'owner': $this->owner = Account::create($arr[$prop]); break; From 4b96475266679fb8feaef1a4b72a9d490009faf3 Mon Sep 17 00:00:00 2001 From: mnichipienko Date: Tue, 6 Feb 2018 11:17:24 +0700 Subject: [PATCH 4/6] user agent --- src/InstagramScraper/Instagram.php | 40 ++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/InstagramScraper/Instagram.php b/src/InstagramScraper/Instagram.php index 21a37af4..feb1305e 100644 --- a/src/InstagramScraper/Instagram.php +++ b/src/InstagramScraper/Instagram.php @@ -30,6 +30,7 @@ class Instagram private $sessionUsername; private $sessionPassword; private $userSession; + private $userAgent = null; public $pagingTimeLimitSec = self::PAGING_TIME_LIMIT_SEC; public $pagingDelayMinimumMicrosec = self::PAGING_DELAY_MINIMUM_MICROSEC; @@ -152,6 +153,35 @@ public function searchAccountsByUsername($username) return $accounts; } + /** + * @param $userAgent + * + * @return string + */ + public function setUserAgent($userAgent) + { + return $this->userAgent = $userAgent; + } + + /** + * @param $userAgent + * + * @return null + */ + public function resetUserAgent($userAgent) + { + return $this->userAgent = null; + } + + /** + * + * @return string + */ + public function getUserAgent() + { + return $this->userAgent; + } + /** * @param $session * @@ -166,11 +196,17 @@ private function generateHeaders($session) $cookies .= "$key=$value; "; } $headers = [ - 'cookie' => $cookies, - 'referer' => Endpoints::BASE_URL . '/', + 'cookie' => $cookies, + 'referer' => Endpoints::BASE_URL . '/', 'x-csrftoken' => $session['csrftoken'], ]; } + + if($this->getUserAgent()) + { + $headers['user-agent'] = $this->getUserAgent(); + } + return $headers; } From a3f44b1acc82f91ddb696f01afae13f8936c0b99 Mon Sep 17 00:00:00 2001 From: shibby Date: Tue, 13 Feb 2018 19:44:32 +0300 Subject: [PATCH 5/6] fix getCurrentTopMediasByTagName --- src/InstagramScraper/Instagram.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/InstagramScraper/Instagram.php b/src/InstagramScraper/Instagram.php index feb1305e..76f89ed3 100644 --- a/src/InstagramScraper/Instagram.php +++ b/src/InstagramScraper/Instagram.php @@ -733,8 +733,9 @@ public function getCurrentTopMediasByTagName($tagName) $this->userSession['csrftoken'] = $cookies['csrftoken']; $jsonResponse = json_decode($response->raw_body, true, 512, JSON_BIGINT_AS_STRING); $medias = []; - foreach ($jsonResponse['tag']['top_posts']['nodes'] as $mediaArray) { - $medias[] = Media::create($mediaArray); + $nodes = (array) @$jsonResponse['graphql']['hashtag']['edge_hashtag_to_media']['edges']; + foreach ($nodes as $mediaArray) { + $medias[] = Media::create($mediaArray['node']); } return $medias; } From 75602918028aba2033b0e896b36852a1fdf59359 Mon Sep 17 00:00:00 2001 From: germanow Date: Sun, 11 Mar 2018 17:12:20 +0200 Subject: [PATCH 6/6] Fix symfony notice --- src/InstagramScraper/Instagram.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/InstagramScraper/Instagram.php b/src/InstagramScraper/Instagram.php index 76f89ed3..159b6833 100644 --- a/src/InstagramScraper/Instagram.php +++ b/src/InstagramScraper/Instagram.php @@ -51,6 +51,7 @@ public static function withCredentials($username, $password, $sessionFolder = nu if (is_string($sessionFolder)) { CacheManager::setDefaultConfig([ 'path' => $sessionFolder, + 'ignoreSymfonyNotice' => true, ]); static::$instanceCache = CacheManager::getInstance('files'); } else {