Skip to content

Commit

Permalink
Merge pull request #239 from rusan/master
Browse files Browse the repository at this point in the history
 Get reel_ids as paramtr. If it empty - it will make a query for get it.
  • Loading branch information
raiym authored Dec 14, 2017
2 parents 6e22178 + 06dae87 commit d94449c
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions src/InstagramScraper/Instagram.php
Original file line number Diff line number Diff line change
Expand Up @@ -907,23 +907,32 @@ public function getFollowing($accountId, $count = 20, $pageSize = 20, $delayed =
return $accounts;
}

public function getStories()
/**
* @param array $reel_ids - array of instagram user ids
* @return array
* @throws InstagramException
*/
public function getStories($reel_ids = null)
{
$response = Request::get(Endpoints::getUserStoriesLink(),
$this->generateHeaders($this->userSession));
$variables = ['precomposed_overlay' => false, 'reel_ids' => []];
if (empty($reel_ids)) {
$response = Request::get(Endpoints::getUserStoriesLink(),
$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.');
}
if ($response->code !== 200) {
throw new InstagramException('Response code is ' . $response->code . '. Body: ' . static::getErrorBody($response->body) . ' Something went wrong. Please report issue.');
}

$jsonResponse = json_decode($response->raw_body, true, 512, JSON_BIGINT_AS_STRING);
if (empty($jsonResponse['data']['user']['feed_reels_tray']['edge_reels_tray_to_reel']['edges'])) {
return [];
}
$jsonResponse = json_decode($response->raw_body, true, 512, JSON_BIGINT_AS_STRING);
if (empty($jsonResponse['data']['user']['feed_reels_tray']['edge_reels_tray_to_reel']['edges'])) {
return [];
}

$variables = ['precomposed_overlay' => false, 'reel_ids' => []];
foreach ($jsonResponse['data']['user']['feed_reels_tray']['edge_reels_tray_to_reel']['edges'] as $edge) {
$variables['reel_ids'][] = $edge['node']['id'];
foreach ($jsonResponse['data']['user']['feed_reels_tray']['edge_reels_tray_to_reel']['edges'] as $edge) {
$variables['reel_ids'][] = $edge['node']['id'];
}
} else {
$variables['reel_ids'] = $reel_ids;
}

$response = Request::get(Endpoints::getStoriesLink($variables),
Expand Down

0 comments on commit d94449c

Please sign in to comment.