diff --git a/composer.json b/composer.json index 3f177622..520491fa 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": ">=5.4.0", + "php": "5.6", "mewlabs/unirest-php": "dev-master", "phpFastCache/phpFastCache": "5.0.*", "ext-curl": "*", diff --git a/src/InstagramScraper/Endpoints.php b/src/InstagramScraper/Endpoints.php index 6145d8b9..b31a2adb 100644 --- a/src/InstagramScraper/Endpoints.php +++ b/src/InstagramScraper/Endpoints.php @@ -38,6 +38,8 @@ class Endpoints const ACCOUNT_MEDIAS2 = 'https://www.instagram.com/graphql/query/?query_id=17880160963012870&id={{accountId}}&first=10&after='; + const ACCOUNT_TAGGED_MEDIA = 'https://www.instagram.com/graphql/query/?query_hash=ff260833edf142911047af6024eb634a&variables={variables}'; + // Look alike?? const URL_SIMILAR = 'https://www.instagram.com/graphql/query/?query_id=17845312237175864&id=4663052'; @@ -110,6 +112,20 @@ public static function getMediasJsonByLocationIdLink($facebookLocationId, $maxId . ($maxId ? ('&max_id=' . $maxId) : ''); } + public static function getAccountTaggedMediaLink($uid, $after = '', $count = 12) + { + $variables = [ + 'id' => $uid, + 'first' => $count, + ]; + + if ($after) { + $variables['after'] = $after; + } + + return str_replace('{variables}', urlencode(json_encode($variables)), static::ACCOUNT_TAGGED_MEDIA); + } + public static function getMediasJsonByTagLink($tag, $maxId = '') { $url = str_replace('{tag}', urlencode($tag), static::MEDIA_JSON_BY_TAG); diff --git a/src/InstagramScraper/Instagram.php b/src/InstagramScraper/Instagram.php index 3930fb11..66e142ad 100644 --- a/src/InstagramScraper/Instagram.php +++ b/src/InstagramScraper/Instagram.php @@ -1076,6 +1076,61 @@ public function getMediasByLocationId($facebookLocationId, $quantity = 24, $offs return $medias; } + /** + * @param integer $uid + * @param string $after + * @param integer $count + * + * @return array + * @throws InstagramException + */ + public function getTaggedMedias($uid, $after = '', $count = 12) + { + $medias = []; + + $toReturn = [ + 'medias' => $medias, + 'maxId' => $after, + 'hasNextPage' => true, + ]; + + $response = Request::get(Endpoints::getAccountTaggedMediaLink($uid, $after, $count), + $this->generateHeaders($this->userSession)); + + if ($response->code !== 200) { + throw new InstagramException('Response code is ' . $response->code . '. Body: ' . static::getErrorBody($response->body) . ' Something went wrong. Please report issue.'); + } + + $this->parseCookies($response->headers); + + $arr = json_decode($response->raw_body, true, 512, JSON_BIGINT_AS_STRING); + + if (!is_array($arr)) { + throw new InstagramException('Response decoding failed. Returned data corrupted or this library outdated. Please report issue'); + } + + if (empty($nodes = $arr['data']['user']['edge_user_to_photos_of_you']['edges'])) { + return $toReturn; + } + + foreach ($nodes as $mediaArray) { + $medias[] = Media::create($mediaArray['node']); + } + + $after = $arr['data']['user']['edge_user_to_photos_of_you']['page_info']['end_cursor']; + $hasNextPage = $arr['data']['user']['edge_user_to_photos_of_you']['page_info']['has_next_page']; + $count = $arr['data']['user']['edge_user_to_photos_of_you']['count']; + + $toReturn = [ + 'medias' => $medias, + 'count' => $count, + 'maxId' => $after, + 'hasNextPage' => $hasNextPage, + ]; + + return $toReturn; + } + /** * @param string $facebookLocationId * @param string $maxId