mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-04-24 23:37:18 +00:00
[InstagramBridge] Add options to reduce 429 errors
First option is session_id of existing Instagram account. Second option is customizing cache timeout for InstagramBridge. Those options can be combined.
This commit is contained in:
parent
9be00ff84e
commit
fb19142a54
@ -6,6 +6,15 @@ class InstagramBridge extends BridgeAbstract {
|
|||||||
const URI = 'https://www.instagram.com/';
|
const URI = 'https://www.instagram.com/';
|
||||||
const DESCRIPTION = 'Returns the newest images';
|
const DESCRIPTION = 'Returns the newest images';
|
||||||
|
|
||||||
|
const CONFIGURATION = array(
|
||||||
|
'session_id' => array(
|
||||||
|
'required' => false,
|
||||||
|
),
|
||||||
|
'cache_timeout' => array(
|
||||||
|
'required' => false,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
const PARAMETERS = array(
|
const PARAMETERS = array(
|
||||||
'Username' => array(
|
'Username' => array(
|
||||||
'u' => array(
|
'u' => array(
|
||||||
@ -50,6 +59,20 @@ class InstagramBridge extends BridgeAbstract {
|
|||||||
const TAG_QUERY_HASH = '9b498c08113f1e09617a1703c22b2f32';
|
const TAG_QUERY_HASH = '9b498c08113f1e09617a1703c22b2f32';
|
||||||
const SHORTCODE_QUERY_HASH = '865589822932d1b43dfe312121dd353a';
|
const SHORTCODE_QUERY_HASH = '865589822932d1b43dfe312121dd353a';
|
||||||
|
|
||||||
|
public function getCacheTimeout() {
|
||||||
|
$customTimeout = $this->getOption('cache_timeout');
|
||||||
|
return $customTimeout || parent::getCacheTimeout();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getContents($uri) {
|
||||||
|
$headers = array();
|
||||||
|
$sessionId = $this->getOption('session_id');
|
||||||
|
if ($sessionId) {
|
||||||
|
$headers[] = 'cookie: sessionid=' . $sessionId;
|
||||||
|
}
|
||||||
|
return getContents($uri, $headers);
|
||||||
|
}
|
||||||
|
|
||||||
protected function getInstagramUserId($username) {
|
protected function getInstagramUserId($username) {
|
||||||
|
|
||||||
if(is_numeric($username)) return $username;
|
if(is_numeric($username)) return $username;
|
||||||
@ -62,8 +85,7 @@ class InstagramBridge extends BridgeAbstract {
|
|||||||
$key = $cache->loadData();
|
$key = $cache->loadData();
|
||||||
|
|
||||||
if($key == null) {
|
if($key == null) {
|
||||||
$data = getContents(self::URI . 'web/search/topsearch/?query=' . $username);
|
$data = $this->getContents(self::URI . 'web/search/topsearch/?query=' . $username);
|
||||||
|
|
||||||
foreach(json_decode($data)->users as $user) {
|
foreach(json_decode($data)->users as $user) {
|
||||||
if(strtolower($user->user->username) === strtolower($username)) {
|
if(strtolower($user->user->username) === strtolower($username)) {
|
||||||
$key = $user->user->pk;
|
$key = $user->user->pk;
|
||||||
@ -202,25 +224,12 @@ class InstagramBridge extends BridgeAbstract {
|
|||||||
return $textContent;
|
return $textContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getSinglePostData($uri) {
|
|
||||||
$shortcode = explode('/', $uri)[4];
|
|
||||||
$data = getContents(self::URI .
|
|
||||||
'graphql/query/?query_hash=' .
|
|
||||||
self::SHORTCODE_QUERY_HASH .
|
|
||||||
'&variables={"shortcode"%3A"' .
|
|
||||||
$shortcode .
|
|
||||||
'"}');
|
|
||||||
|
|
||||||
return json_decode($data)->data->shortcode_media;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getInstagramJSON($uri) {
|
protected function getInstagramJSON($uri) {
|
||||||
|
|
||||||
if(!is_null($this->getInput('u'))) {
|
if(!is_null($this->getInput('u'))) {
|
||||||
|
|
||||||
$userId = $this->getInstagramUserId($this->getInput('u'));
|
$userId = $this->getInstagramUserId($this->getInput('u'));
|
||||||
|
$data = $this->getContents(self::URI .
|
||||||
$data = getContents(self::URI .
|
|
||||||
'graphql/query/?query_hash=' .
|
'graphql/query/?query_hash=' .
|
||||||
self::USER_QUERY_HASH .
|
self::USER_QUERY_HASH .
|
||||||
'&variables={"id"%3A"' .
|
'&variables={"id"%3A"' .
|
||||||
@ -229,12 +238,13 @@ class InstagramBridge extends BridgeAbstract {
|
|||||||
return json_decode($data);
|
return json_decode($data);
|
||||||
|
|
||||||
} elseif(!is_null($this->getInput('h'))) {
|
} elseif(!is_null($this->getInput('h'))) {
|
||||||
$data = getContents(self::URI .
|
$data = $this->getContents(self::URI .
|
||||||
'graphql/query/?query_hash=' .
|
'graphql/query/?query_hash=' .
|
||||||
self::TAG_QUERY_HASH .
|
self::TAG_QUERY_HASH .
|
||||||
'&variables={"tag_name"%3A"' .
|
'&variables={"tag_name"%3A"' .
|
||||||
$this->getInput('h') .
|
$this->getInput('h') .
|
||||||
'"%2C"first"%3A10}');
|
'"%2C"first"%3A10}');
|
||||||
|
|
||||||
return json_decode($data);
|
return json_decode($data);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user