Skip to content

Commit

Permalink
Use stored session when checking logged-in status (#1030)
Browse files Browse the repository at this point in the history
* Use InstagramException as a base exception class.

* Try to use stored session when checking logged-in status.

Co-authored-by: test <test>
  • Loading branch information
devaskim authored Jan 26, 2022
1 parent 7e21067 commit 3c13ebe
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/InstagramScraper/Exception/InstagramAuthException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace InstagramScraper\Exception;

class InstagramAuthException extends \Exception
class InstagramAuthException extends InstagramException
{
public function __construct($message = "", $code = 401, $previous = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace InstagramScraper\Exception;

class InstagramNotFoundException extends \Exception
class InstagramNotFoundException extends InstagramException
{
public function __construct($message = "", $code = 404, $previous = null)
{
Expand Down
20 changes: 12 additions & 8 deletions src/InstagramScraper/Instagram.php
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ public function getMediaByUrl($mediaUrl)
if (!isset($mediaArray['items'])) {
throw new InstagramException('Media with this code does not exist');
}
return Media::create(current($mediaArray['items']));
return Media::create(current($mediaArray['items']));
}

/**
Expand Down Expand Up @@ -1205,7 +1205,7 @@ public function getMediasByTag($tag, $count = 12, $maxId = '', $minTimestamp = n
throw new InstagramException('Response decoding failed. Returned data corrupted or this library outdated. Please report issue');
}
$rootKey = array_key_exists('graphql', $arr) ? 'graphql' : 'data';

if (empty($arr[$rootKey]['hashtag']['edge_hashtag_to_media']['count'])) {
return [];
}
Expand Down Expand Up @@ -1800,10 +1800,10 @@ public function getPaginateAllFollowing($accountId, $pageSize = 20, $nextPage =
}

/**
* Search users by followers
* Search users by followers
* @param string $accountId Account id of the profile to query
* @param string $query Query to search by followers
*
*
* @return array
* @throws InstagramException
*/
Expand Down Expand Up @@ -1836,10 +1836,10 @@ public function searchFollowers($accountId, $query = '')
}

/**
* Search users by following
* Search users by following
* @param string $accountId Account id of the profile to query
* @param string $query Query to search by following
*
*
* @return array
* @throws InstagramException
*/
Expand Down Expand Up @@ -2058,11 +2058,15 @@ public function getCacheKey()
*
* @return bool
*/
public function isLoggedIn($session)
public function isLoggedIn($session = null)
{
if ($session === null || !isset($session['sessionid'])) {
if ($session === null) {
$session = static::$instanceCache->get($this->getCacheKey());
}
if (!isset($session['sessionid'])) {
return false;
}

$sessionId = $session['sessionid'];
$csrfToken = $session['csrftoken'];
$headers = [
Expand Down

0 comments on commit 3c13ebe

Please sign in to comment.