Skip to content

Commit 3c13ebe

Browse files
authored
Use stored session when checking logged-in status (#1030)
* Use InstagramException as a base exception class. * Try to use stored session when checking logged-in status. Co-authored-by: test <test>
1 parent 7e21067 commit 3c13ebe

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

src/InstagramScraper/Exception/InstagramAuthException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace InstagramScraper\Exception;
44

5-
class InstagramAuthException extends \Exception
5+
class InstagramAuthException extends InstagramException
66
{
77
public function __construct($message = "", $code = 401, $previous = null)
88
{

src/InstagramScraper/Exception/InstagramNotFoundException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace InstagramScraper\Exception;
44

5-
class InstagramNotFoundException extends \Exception
5+
class InstagramNotFoundException extends InstagramException
66
{
77
public function __construct($message = "", $code = 404, $previous = null)
88
{

src/InstagramScraper/Instagram.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ public function getMediaByUrl($mediaUrl)
822822
if (!isset($mediaArray['items'])) {
823823
throw new InstagramException('Media with this code does not exist');
824824
}
825-
return Media::create(current($mediaArray['items']));
825+
return Media::create(current($mediaArray['items']));
826826
}
827827

828828
/**
@@ -1205,7 +1205,7 @@ public function getMediasByTag($tag, $count = 12, $maxId = '', $minTimestamp = n
12051205
throw new InstagramException('Response decoding failed. Returned data corrupted or this library outdated. Please report issue');
12061206
}
12071207
$rootKey = array_key_exists('graphql', $arr) ? 'graphql' : 'data';
1208-
1208+
12091209
if (empty($arr[$rootKey]['hashtag']['edge_hashtag_to_media']['count'])) {
12101210
return [];
12111211
}
@@ -1800,10 +1800,10 @@ public function getPaginateAllFollowing($accountId, $pageSize = 20, $nextPage =
18001800
}
18011801

18021802
/**
1803-
* Search users by followers
1803+
* Search users by followers
18041804
* @param string $accountId Account id of the profile to query
18051805
* @param string $query Query to search by followers
1806-
*
1806+
*
18071807
* @return array
18081808
* @throws InstagramException
18091809
*/
@@ -1836,10 +1836,10 @@ public function searchFollowers($accountId, $query = '')
18361836
}
18371837

18381838
/**
1839-
* Search users by following
1839+
* Search users by following
18401840
* @param string $accountId Account id of the profile to query
18411841
* @param string $query Query to search by following
1842-
*
1842+
*
18431843
* @return array
18441844
* @throws InstagramException
18451845
*/
@@ -2058,11 +2058,15 @@ public function getCacheKey()
20582058
*
20592059
* @return bool
20602060
*/
2061-
public function isLoggedIn($session)
2061+
public function isLoggedIn($session = null)
20622062
{
2063-
if ($session === null || !isset($session['sessionid'])) {
2063+
if ($session === null) {
2064+
$session = static::$instanceCache->get($this->getCacheKey());
2065+
}
2066+
if (!isset($session['sessionid'])) {
20642067
return false;
20652068
}
2069+
20662070
$sessionId = $session['sessionid'];
20672071
$csrfToken = $session['csrftoken'];
20682072
$headers = [

0 commit comments

Comments
 (0)