Skip to content

Commit

Permalink
Merge pull request #455 from mewlabs/fix-444
Browse files Browse the repository at this point in the history
fix of issue #444 (Using $this when not in object context)
  • Loading branch information
raiym authored Feb 14, 2019
2 parents bb619f0 + 87bb7db commit d5aa635
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/InstagramScraper/Instagram.php
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ public function getMediaCommentsByCode($code, $count = 10, $maxId = null)
if (static::HTTP_OK !== $response->code) {
throw new InstagramException('Response code is ' . $response->code . '. Body: ' . static::getErrorBody($response->body) . ' Something went wrong. Please report issue.', $response->code);
}
$cookies = static::parseCookies($response->headers);
$this->parseCookies($response->headers);
$jsonResponse = $this->decodeRawBodyToJson($response->raw_body);
$nodes = $jsonResponse['data']['shortcode_media']['edge_media_to_comment']['edges'];
foreach ($nodes as $commentArray) {
Expand Down Expand Up @@ -685,9 +685,9 @@ public function getMediaCommentsByCode($code, $count = 10, $maxId = null)
*
* @return array
*/
private static function parseCookies($headers)
private function parseCookies($headers)
{
$rawCookies = isset($headers['Set-Cookie']) ? $headers['Set-Cookie'] : isset($headers['set-cookie']) ? $headers['set-cookie'] : [];
$rawCookies = isset($headers['Set-Cookie']) ? $headers['Set-Cookie'] : (isset($headers['set-cookie']) ? $headers['set-cookie'] : []);

if (!is_array($rawCookies)) {
$rawCookies = [$rawCookies];
Expand Down Expand Up @@ -754,7 +754,7 @@ public function getMediaLikesByCode($code, $count = 10, $maxId = null)
if ($response->code !== static::HTTP_OK) {
throw new InstagramException('Response code is ' . $response->code . '. Body: ' . $response->body . ' Something went wrong. Please report issue.', $response->code);
}
$cookies = self::parseCookies($response->headers['Set-Cookie']);
$this->parseCookies($response->headers);

$jsonResponse = $this->decodeRawBodyToJson($response->raw_body);

Expand Down Expand Up @@ -843,7 +843,7 @@ public function getMediasByTag($tag, $count = 12, $maxId = '', $minTimestamp = n
throw new InstagramException('Response code is ' . $response->code . '. Body: ' . static::getErrorBody($response->body) . ' Something went wrong. Please report issue.', $response->code);
}

$cookies = static::parseCookies($response->headers);
$this->parseCookies($response->headers);

$arr = $this->decodeRawBodyToJson($response->raw_body);

Expand Down Expand Up @@ -904,7 +904,7 @@ public function getPaginateMediasByTag($tag, $maxId = '')
throw new InstagramException('Response code is ' . $response->code . '. Body: ' . static::getErrorBody($response->body) . ' Something went wrong. Please report issue.', $response->code);
}

$cookies = static::parseCookies($response->headers);
$this->parseCookies($response->headers);

$arr = $this->decodeRawBodyToJson($response->raw_body);

Expand Down Expand Up @@ -959,7 +959,7 @@ public function getCurrentTopMediasByTagName($tagName)
throw new InstagramException('Response code is ' . $response->code . '. Body: ' . static::getErrorBody($response->body) . ' Something went wrong. Please report issue.');
}

$cookies = static::parseCookies($response->headers);
$this->parseCookies($response->headers);
$jsonResponse = $this->decodeRawBodyToJson($response->raw_body);
$medias = [];
$nodes = (array)@$jsonResponse['graphql']['hashtag']['edge_hashtag_to_top_posts']['edges'];
Expand All @@ -986,7 +986,7 @@ public function getCurrentTopMediasByLocationId($facebookLocationId)
if ($response->code !== static::HTTP_OK) {
throw new InstagramException('Response code is ' . $response->code . '. Body: ' . static::getErrorBody($response->body) . ' Something went wrong. Please report issue.', $response->code);
}
$cookies = static::parseCookies($response->headers);
$this->parseCookies($response->headers);
$jsonResponse = $this->decodeRawBodyToJson($response->raw_body);
$nodes = $jsonResponse['location']['top_posts']['nodes'];
$medias = [];
Expand Down Expand Up @@ -1015,7 +1015,7 @@ public function getMediasByLocationId($facebookLocationId, $quantity = 24, $offs
if ($response->code !== static::HTTP_OK) {
throw new InstagramException('Response code is ' . $response->code . '. Body: ' . static::getErrorBody($response->body) . ' Something went wrong. Please report issue.', $response->code);
}
$cookies = static::parseCookies($response->headers);
$this->parseCookies($response->headers);
$arr = $this->decodeRawBodyToJson($response->raw_body);
$nodes = $arr['graphql']['location']['edge_location_to_media']['edges'];
foreach ($nodes as $mediaArray) {
Expand Down Expand Up @@ -1053,7 +1053,7 @@ public function getLocationById($facebookLocationId)
throw new InstagramException('Response code is ' . $response->code . '. Body: ' . static::getErrorBody($response->body) . ' Something went wrong. Please report issue.', $response->code);
}

$cookies = static::parseCookies($response->headers);
$this->parseCookies($response->headers);
$jsonResponse = $this->decodeRawBodyToJson($response->raw_body);
return Location::create($jsonResponse['graphql']['location']);
}
Expand Down Expand Up @@ -1271,7 +1271,7 @@ public function login($force = false, $support_two_step_verification = false)
if (isset($match[1])) {
$csrfToken = $match[1];
}
$cookies = static::parseCookies($response->headers);
$cookies = $this->parseCookies($response->headers);

$mid = $cookies['mid'];
$headers = [
Expand Down Expand Up @@ -1300,7 +1300,7 @@ public function login($force = false, $support_two_step_verification = false)
}
}

$cookies = static::parseCookies($response->headers);
$cookies = $this->parseCookies($response->headers);

$cookies['mid'] = $mid;
$cachedString->set($cookies);
Expand Down Expand Up @@ -1336,7 +1336,7 @@ public function isLoggedIn($session)
if ($response->code !== static::HTTP_OK) {
return false;
}
$cookies = static::parseCookies($response->headers);
$cookies = $this->parseCookies($response->headers);
if (!isset($cookies['ds_user_id'])) {
return false;
}
Expand All @@ -1351,7 +1351,7 @@ public function isLoggedIn($session)
*/
private function verifyTwoStep($response, $cookies)
{
$new_cookies = static::parseCookies($response->headers);
$new_cookies = $this->parseCookies($response->headers);
$cookies = array_merge($cookies, $new_cookies);
$cookie_string = '';
foreach ($cookies as $name => $value) {
Expand Down

0 comments on commit d5aa635

Please sign in to comment.