From c2e5d62ed4ccb051941baa47d28730b070630229 Mon Sep 17 00:00:00 2001 From: Pierre Grimaud Date: Tue, 2 Aug 2022 18:01:47 +0200 Subject: [PATCH] Fix user agent on timeline --- src/Instagram/Transport/TimelineDataFeed.php | 8 +++++--- tests/TimelineTest.php | 10 ++-------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/Instagram/Transport/TimelineDataFeed.php b/src/Instagram/Transport/TimelineDataFeed.php index b1e6fe2..9411d17 100644 --- a/src/Instagram/Transport/TimelineDataFeed.php +++ b/src/Instagram/Transport/TimelineDataFeed.php @@ -8,7 +8,7 @@ use GuzzleHttp\Exception\ClientException; use Instagram\Exception\InstagramFetchException; use Instagram\Utils\Endpoints; -use Instagram\Utils\UserAgentHelper; +use Instagram\Utils\OptionHelper; class TimelineDataFeed extends AbstractDataFeed { @@ -52,7 +52,8 @@ public function fetchDataNewFeedPostExist(): array $options = [ 'headers' => [ - 'user-agent' => UserAgentHelper::AGENT_DEFAULT, + 'user-agent' => OptionHelper::$USER_AGENT, + 'accept-language' => OptionHelper::$LOCALE, 'x-csrftoken' => $csrfToken, 'x-ig-app-id' => self::IG_APP_ID, ], @@ -99,7 +100,8 @@ public function fetchDataTimelineFeed(string $maxId = null): array $options = [ 'headers' => [ - 'user-agent' => UserAgentHelper::AGENT_DEFAULT, + 'user-agent' => OptionHelper::$USER_AGENT, + 'accept-language' => OptionHelper::$LOCALE, 'x-csrftoken' => $csrfToken, 'x-ig-app-id' => self::IG_APP_ID, ], diff --git a/tests/TimelineTest.php b/tests/TimelineTest.php index 473409e..4cabb4d 100644 --- a/tests/TimelineTest.php +++ b/tests/TimelineTest.php @@ -2,15 +2,11 @@ namespace Instagram\Tests; -use GuzzleHttp\{Client, Cookie\CookieJar, Cookie\SetCookie, Handler\MockHandler, HandlerStack, Psr7\Response}; +use GuzzleHttp\{Client, Handler\MockHandler, HandlerStack, Psr7\Response}; use Instagram\Api; -use Instagram\Auth\Session; use Instagram\Exception\InstagramFetchException; -use Instagram\Model\Hashtag; -use Instagram\Model\Media; -use Instagram\Model\Profile; -use Instagram\Model\Reels; +use Instagram\Model\User; use PHPUnit\Framework\TestCase; use Symfony\Component\Cache\Adapter\FilesystemAdapter; @@ -36,14 +32,12 @@ public function testValidTimelineFetch() $api->login('username', 'password'); - /** @var TimelineFeed $timelineFeed */ $timelineFeed = $api->getTimeline(); $this->assertCount(12, $timelineFeed->getTimeline()); $this->assertTrue($timelineFeed->hasMoreTimeline()); $this->assertSame('KGEAReU-f8agKifHBbQo8T4qJ4yFuozqEConTT6FHc4VKifY8SaNeHQqJ99NuNQaGConYrO-huzAKicjvhc_PzEqJySfsjT-PionLboxQ5wiKyeuQb8y5Z8qJzZWMDYKFionFsr24sCKYEYCKQQZBCIA', $timelineFeed->getMaxId()); - /** @var Timeline $firstTimeline */ $firstTimeline = current($timelineFeed->getTimeline()); $this->assertSame("carousel", $firstTimeline->getType());