Skip to content

Commit

Permalink
Merge pull request #339 from yazhog/feature
Browse files Browse the repository at this point in the history
getAccount from sharedData
  • Loading branch information
raiym authored Apr 13, 2018
2 parents 968471b + 21dd8e0 commit 87ddba9
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/InstagramScraper/Instagram.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,19 +281,21 @@ public function getMedias($username, $count = 20, $maxId = '')
*/
public function getAccount($username)
{
$response = Request::get(Endpoints::getAccountJsonLink($username), $this->generateHeaders($this->userSession));
$response = Request::get(Endpoints::getAccountPageLink($username), $this->generateHeaders($this->userSession));
if (static::HTTP_NOT_FOUND === $response->code) {
throw new InstagramNotFoundException('Account with given username does not exist.');
}
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.');
}

$userArray = json_decode($response->raw_body, true, 512, JSON_BIGINT_AS_STRING);
if (!isset($userArray['graphql']['user'])) {
preg_match_all('#\_sharedData \= (.*?)\;\<\/script\>#', $response->raw_body, $out);
$userArray = json_decode($out[1][0], true, 512, JSON_BIGINT_AS_STRING);

if (!isset($userArray['entry_data']['ProfilePage'][0]['graphql']['user'])) {
throw new InstagramNotFoundException('Account with this username does not exist', 404);
}
return Account::create($userArray['graphql']['user']);
return Account::create($userArray['entry_data']['ProfilePage'][0]['graphql']['user']);
}

/**
Expand Down

0 comments on commit 87ddba9

Please sign in to comment.