diff --git a/examples/story-highlights-by-id-folder.php b/examples/story-highlights-by-id-folder.php new file mode 100644 index 0000000..fa90a76 --- /dev/null +++ b/examples/story-highlights-by-id-folder.php @@ -0,0 +1,28 @@ +login($credentials->getLogin(), $credentials->getPassword()); + + // url is https://www.instagram.com/stories/highlights/17924739640580662/ + $folder = $api->getStoriesOfHighlightsFolderById(17924739640580662); + dd($folder->getStories()); + +} catch (InstagramException $e) { + print_r($e->getMessage()); +} catch (CacheException $e) { + print_r($e->getMessage()); +} diff --git a/src/Instagram/Api.php b/src/Instagram/Api.php index 2e0692d..a3f0ac1 100644 --- a/src/Instagram/Api.php +++ b/src/Instagram/Api.php @@ -713,4 +713,20 @@ public function commentPost(int $postId, string $message): string $request = new CommentPost($this->client, $this->session); return $request->comment($postId, $message); } + + /** + * @param int $folderId + * + * @return StoryHighlightsFolder + * + * @throws Exception\InstagramAuthException + * @throws Exception\InstagramFetchException + */ + public function getStoriesOfHighlightsFolderById(int $folderId): StoryHighlightsFolder + { + $storyFolder = new StoryHighlightsFolder(); + $storyFolder->setId($folderId); + + return $this->getStoriesOfHighlightsFolder($storyFolder); + } } diff --git a/src/Instagram/Model/StoryHighlightsFolder.php b/src/Instagram/Model/StoryHighlightsFolder.php index b1545af..9aaa4e2 100644 --- a/src/Instagram/Model/StoryHighlightsFolder.php +++ b/src/Instagram/Model/StoryHighlightsFolder.php @@ -100,9 +100,13 @@ public function addStory(StoryMedia $story): void /** * @return StoryMedia[] */ - public function getStories(): array + public function getStories(bool $oldestInFirst = true): array { - return array_reverse($this->stories); + if ($oldestInFirst) { + return array_reverse($this->stories); + } else { + return $this->stories; + } } public function orderStories(): void diff --git a/tests/StoriesTest.php b/tests/StoriesTest.php index e671324..38591d0 100644 --- a/tests/StoriesTest.php +++ b/tests/StoriesTest.php @@ -103,4 +103,31 @@ public function testHighlightsStoriesFetch() $api->logout('username'); } + + public function testHighlightsStoriesByIdFetch() + { + $cachePool = new FilesystemAdapter('Instagram', 0, __DIR__ . '/cache'); + + $mock = new MockHandler([ + new Response(200, ['Set-Cookie' => 'cookie'], file_get_contents(__DIR__ . '/fixtures/home.html')), + new Response(200, [], file_get_contents(__DIR__ . '/fixtures/login-success.json')), + new Response(200, [], file_get_contents(__DIR__ . '/fixtures/highlights-stories.json')), + ]); + + $handlerStack = HandlerStack::create($mock); + $client = new Client(['handler' => $handlerStack]); + + $api = new Api($cachePool, $client); + + // clear cache + $api->logout('username'); + + $api->login('username', 'password'); + + $storyFolder = $api->getStoriesOfHighlightsFolderById(12345); + + $this->assertCount(33, $storyFolder->getStories(false)); + + $api->logout('username'); + } }