Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getAccount() fixed to get all missing user data. #1118

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/InstagramScraper/Endpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Endpoints
{
const BASE_URL = 'https://www.instagram.com';
const LOGIN_URL = 'https://www.instagram.com/accounts/login/ajax/';
const ACCOUNT_PAGE = 'https://www.instagram.com/{username}/';
const ACCOUNT_PAGE = 'https://www.instagram.com/api/v1/users/web_profile_info/?username={username}';
const MEDIA_LINK = 'https://www.instagram.com/p/{code}';
const ACCOUNT_MEDIAS = 'https://www.instagram.com/graphql/query/?query_hash=e769aa130647d2354c40ea6a439bfc08&variables={variables}';
const ACCOUNT_TAGGED_MEDIAS = 'https://www.instagram.com/graphql/query/?query_hash=be13233562af2d229b008d2976b998b5&variables={variables}';
Expand Down
11 changes: 7 additions & 4 deletions src/InstagramScraper/Instagram.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ private function generateHeaders($session, $gisToken = null)

}

//user agent to retrieve account data
$this->setUserAgent("Instagram 219.0.0.12.117 Android");

if ($this->getUserAgent()) {
$headers['user-agent'] = $this->getUserAgent();

Expand Down Expand Up @@ -738,11 +741,11 @@ public function getAccount($username)
throw new InstagramAgeRestrictedException('Account with given username is age-restricted.');
}

if (!isset($userArray['entry_data']['ProfilePage'][0]['graphql']['user'])) {
if (!isset($userArray['entry_data']['ProfilePage'][0]['graphql']['user']) && !isset($userArray['data']['user'])) {
throw new InstagramException('Response code is ' . $response->code . ': ' . static::httpCodeToString($response->code) . '.' .
'Something went wrong. Please report issue.', $response->code, static::getErrorBody($response->body));
}
return Account::create($userArray['entry_data']['ProfilePage'][0]['graphql']['user']);
return Account::create($userArray['entry_data']['ProfilePage'][0]['graphql']['user']?? $userArray['data']['user']);
}

public function getAccountInfo($username)
Expand Down Expand Up @@ -772,7 +775,7 @@ private static function extractSharedDataFromBody($body)
if (preg_match_all('#\_sharedData \= (.*?)\;\<\/script\>#', $body, $out)) {
return json_decode($out[1][0], true, 512, JSON_BIGINT_AS_STRING);
}
return null;
return json_decode($body, true, 512, JSON_BIGINT_AS_STRING);
}

private function isAccountAgeRestricted($userArray, $body)
Expand Down Expand Up @@ -1430,7 +1433,7 @@ public function getMediasByTag($tag, $count = 12, $maxId = '', $minTimestamp = n
if (empty($nodes)) {
return $medias;
}
$maxId = $arr[$rootKey]['recent']['next_max_id']; // $arr[$rootKey]['hashtag']['edge_hashtag_to_media']['page_info']['end_cursor'];
$maxId = $arr[$rootKey]['recent']['next_max_id']?? ''; // $arr[$rootKey]['hashtag']['edge_hashtag_to_media']['page_info']['end_cursor'];
$hasNextPage = $arr[$rootKey]['recent']['more_available']; // $arr[$rootKey]['hashtag']['edge_hashtag_to_media']['page_info']['has_next_page'];
}
return $medias;
Expand Down