Skip to content

Commit

Permalink
[InstagramBridge] Fix Instagram stories and user id finding.
Browse files Browse the repository at this point in the history
  • Loading branch information
teromene committed Sep 11, 2019
1 parent ccef6b9 commit 48ebed7
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions bridges/InstagramBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class InstagramBridge extends BridgeAbstract {

const USER_QUERY_HASH = '58b6785bea111c67129decbe6a448951';
const TAG_QUERY_HASH = '174a5243287c5f3a7de741089750ab3b';
const STORY_QUERY_HASH = '865589822932d1b43dfe312121dd353a';

protected function getInstagramUserId($username) {

Expand All @@ -56,9 +57,17 @@ protected function getInstagramUserId($username) {
$cache->setKey([$username]);
$key = $cache->loadData();

if($key == null) {
if($key == null || true) {

This comment has been minimized.

Copy link
@em92

em92 Sep 11, 2019

Contributor

Always true

This comment has been minimized.

Copy link
@teromene

teromene Sep 11, 2019

Author Member

Forgot this indeed

$data = getContents(self::URI . 'web/search/topsearch/?query=' . $username);
$key = json_decode($data)->users[0]->user->pk;

foreach(json_decode($data)->users as $user) {
if($user->user->username === $username) {

This comment has been minimized.

Copy link
@lllusion3469

lllusion3469 Sep 17, 2019

Aren't usernames case-insensitive?

A username returned by the API may not be the same case as the $username passed to the function but still refer to the same user.

Edit: the cache messes with the results when first trying the working version and then changing some letter to uppercase

$key = $user->user->pk;
}
}
if($key == null) {
returnServerError('Unable to find username in search result.');

This comment has been minimized.

Copy link
@lllusion3469

lllusion3469 Sep 17, 2019

wouldn't it be somewhat more appropriate to return a 404 like it did previously (implicitly through getContents)

}
$cache->saveData($key);
}
return $key;
Expand Down Expand Up @@ -122,6 +131,7 @@ public function collectData(){
}

if(!is_null($this->getInput('u')) && $media->__typename == 'GraphSidecar') {

$data = $this->getInstagramStory($item['uri']);
$item['content'] = $data[0];
$item['enclosures'] = $data[1];
Expand All @@ -141,8 +151,15 @@ public function collectData(){

protected function getInstagramStory($uri) {

$data = $this->getInstagramJSON($uri);
$mediaInfo = $data->entry_data->PostPage[0]->graphql->shortcode_media;
$shortcode = explode('/', $uri)[4];
$data = getContents(self::URI .
'graphql/query/?query_hash=' .
self::STORY_QUERY_HASH .
'&variables={"shortcode"%3A"' .
$shortcode .
'"}');

$mediaInfo = json_decode($data)->data->shortcode_media;

//Process the first element, that isn't in the node graph
if (count($mediaInfo->edge_media_to_caption->edges) > 0) {
Expand Down

0 comments on commit 48ebed7

Please sign in to comment.