Skip to content

Commit

Permalink
Remove rhxGis parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrimaud committed May 18, 2019
1 parent f4800aa commit 2c9b1b7
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 28 deletions.
48 changes: 47 additions & 1 deletion examples/medias.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,53 @@
echo '============================' . "\n";
}

// Second Page
// Second page

$api->setEndCursor($feed->getEndCursor());

sleep(1); // avoir 429 Rate limit from Instagram

$feed = $api->getFeed();

echo "\n\n";
echo '============================' . "\n";
echo 'Medias third page : ' . "\n";
echo '============================' . "\n\n";

/** @var \Instagram\Hydrator\Component\Media $media */
foreach ($feed->getMedias() as $media) {
echo 'ID : ' . $media->getId() . "\n";
echo 'Caption : ' . $media->getCaption() . "\n";
echo 'Link : ' . $media->getLink() . "\n";
echo 'Likes : ' . $media->getLikes() . "\n";
echo 'Date : ' . $media->getDate()->format('Y-m-d h:i:s') . "\n";
echo '============================' . "\n";
}

// Third page

$api->setEndCursor($feed->getEndCursor());

sleep(1); // avoir 429 Rate limit from Instagram

$feed = $api->getFeed();

echo "\n\n";
echo '============================' . "\n";
echo 'Medias fourth page : ' . "\n";
echo '============================' . "\n\n";

/** @var \Instagram\Hydrator\Component\Media $media */
foreach ($feed->getMedias() as $media) {
echo 'ID : ' . $media->getId() . "\n";
echo 'Caption : ' . $media->getCaption() . "\n";
echo 'Link : ' . $media->getLink() . "\n";
echo 'Likes : ' . $media->getLikes() . "\n";
echo 'Date : ' . $media->getDate()->format('Y-m-d h:i:s') . "\n";
echo '============================' . "\n";
}

// Fourth Page

$api->setEndCursor($feed->getEndCursor());

Expand Down
21 changes: 0 additions & 21 deletions src/Instagram/Storage/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@

class Cache
{
/**
* @var string
*/
public $rhxGis;

/**
* @var int
*/
Expand All @@ -19,22 +14,6 @@ class Cache
*/
public $cookie = [];

/**
* @return string
*/
public function getRhxGis()
{
return $this->rhxGis;
}

/**
* @param string $rhxGis
*/
public function setRhxGis($rhxGis)
{
$this->rhxGis = $rhxGis;
}

/**
* @return array
*/
Expand Down
1 change: 0 additions & 1 deletion src/Instagram/Transport/HtmlTransportFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public function fetchData($userName)

if ($this->cacheManager instanceof CacheManager) {
$newCache = new Cache();
$newCache->setRhxGis($data->rhx_gis);
$newCache->setUserId($data->entry_data->ProfilePage[0]->graphql->user->id);
if ($res->hasHeader('Set-Cookie')) {
$newCache->setCookie($res->getHeaders()['Set-Cookie']);
Expand Down
8 changes: 3 additions & 5 deletions src/Instagram/Transport/JsonTransportFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ public function __construct(Client $client, $endCursor, CacheManager $cacheManag
}

/**
* @param $rhxgis
* @param $variables
*
* @return string
*/
private function generateGis($rhxgis, $variables)
private function generateGis($variables)
{
return md5($rhxgis . ':' . json_encode($variables));
return md5(json_encode($variables));
}

/**
Expand Down Expand Up @@ -66,7 +65,7 @@ public function fetchData($userName, $limit)
'headers' => [
'user-agent' => self::USER_AGENT,
'x-requested-with' => 'XMLHttpRequest',
'x-instagram-gis' => $this->generateGis($cache->getRhxGis(), $variables)
'x-instagram-gis' => $this->generateGis($variables)
],
'cookies' => $cookieJar
];
Expand All @@ -84,7 +83,6 @@ public function fetchData($userName, $limit)

// save to cache for next request
$newCache = new Cache();
$newCache->setRhxGis($cache->getRhxGis());
$newCache->setUserId($cache->getUserId());
if ($res->hasHeader('Set-Cookie')) {
$newCache->setCookie($res->getHeaders()['Set-Cookie']);
Expand Down

0 comments on commit 2c9b1b7

Please sign in to comment.