Skip to content

Commit

Permalink
fixed error on getStories with no arguments (added in getStoriesLink …
Browse files Browse the repository at this point in the history
…and call to getStoriesLink in getStories). +example that explains working of userstories - stories - story (#832)
  • Loading branch information
ricdijk authored Dec 21, 2020
1 parent 845d2a1 commit 7c9e479
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
57 changes: 57 additions & 0 deletions examples/getStoriesFromUserStories.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
ini_set('display_errors', 1);ini_set('display_startup_errors', 1);error_reporting(E_ALL);

require __DIR__ . '/../vendor/autoload.php';
use Phpfastcache\Helper\Psr16Adapter;

$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'user', 'passed', new Psr16Adapter('Files'));
$instagram->login();
$instagram->saveSession();


// *************************** get storie from unsetStories **********************************
/* getStories returns the following imap_fetchstructure (class Story extends Media, can be treated as Media, however no 'owner' in Stories -> owner in UserStories)
- Array
- UserStories
- Owner
- Stories
- Story
- Story
- Story
- ....
- UserStories
- Owner
- Stories
- Story
- Story
- Story
- ....
- .....
*/
// Get userStories
$userStories = $instagram->getStories();

//For each userStorie => get Stories
for ($i=0; $i<count($userStories);$i++)
{
$stories = $userStories[$i]->getStories();
$owner = $userStories[$i]->getOwner();
echo "\n<br>===========================================================";
echo "\n<br>UserStorie: " . $i;
echo "\n<br>Id: " . $owner['id'];
echo "\n<br>UserName: " . $owner['username'];

//for each stories => get Story
for ($j=0; $j<count($stories);$j++)
{
$story = $stories[$j];
echo "\n<br>--------------------------------------------------------";
echo "\n<br>Storie: " . $j;
echo "\n<br>Id: " . $story['id'];
echo "\n<br>Creation Time: " . $story['createdTime'];
echo "\n<br>Type: " . $story['type'];
echo "\n<br><img height=100 src=\"".$story['imageThumbnailUrl']."\">";

}
}
?>
4 changes: 2 additions & 2 deletions src/InstagramScraper/Endpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ public static function getFollowingJsonLink($accountId, $count, $after = '')
return $url;
}

public static function getUserStoriesLink()
public static function getUserStoriesLink($variables=[])
{
$url = self::getGraphQlUrl(InstagramQueryId::USER_STORIES, ['variables' => json_encode([])]);
$url = self::getGraphQlUrl(InstagramQueryId::USER_STORIES, ['variables' => json_encode($variables)]);
return $url;
}

Expand Down
2 changes: 1 addition & 1 deletion src/InstagramScraper/Instagram.php
Original file line number Diff line number Diff line change
Expand Up @@ -1548,7 +1548,7 @@ public function getStories($reel_ids = null)
{
$variables = ['precomposed_overlay' => false, 'reel_ids' => []];
if (empty($reel_ids)) {
$response = Request::get(Endpoints::getUserStoriesLink(),
$response = Request::get(Endpoints::getUserStoriesLink($variables),
$this->generateHeaders($this->userSession));

if ($response->code !== static::HTTP_OK) {
Expand Down

0 comments on commit 7c9e479

Please sign in to comment.