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

Do not hydrate media or IGTV loaded with profile data #362

Merged
merged 3 commits into from
Dec 23, 2023
Merged
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ composer require pgrimaud/instagram-user-feed

# Changelog

**vNEXT** - 2023-12-222:

- Medias are no longer returned after fetching a profile. `$profile->getMedias()` will always
return an empty array after calling `$api->getProfile()`. It is necessary to call
`$api->getMoreMedias($profile)` to return the first 12 media
- Same for IGTV

**v6.16** - 2022-08-02:

- Login with cookies. Thanks to [nsmle](https://github.com/nsmle) (example [here](https://github.com/pgrimaud/instagram-user-feed/blob/master/examples/login-with-cookies.php)) 🎉.
Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,8 @@
"php-coveralls/php-coveralls": "^2.2",
"phpunit/phpunit": "^8.5|^9.5",
"symfony/var-dumper": "^5.0|^6.0"
},
"scripts": {
"test": "phpunit tests --whitelist src"
}
}
2 changes: 0 additions & 2 deletions src/Instagram/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -790,8 +790,6 @@ public function getProfile(string $user): Profile

$hydrator = new ProfileHydrator();
$hydrator->hydrateProfile($data);
$hydrator->hydrateMedias($data);
$hydrator->hydrateIgtvs($data);

return $hydrator->getProfile();
}
Expand Down
4 changes: 4 additions & 0 deletions src/Instagram/Hydrator/ProfileHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ public function hydrateIgtvs(\StdClass $data): void
// reset igtvs
$this->profile->setIGTV([]);

if(!isset($data->edge_felix_video_timeline->edges)) {
return;
}

foreach ($data->edge_felix_video_timeline->edges as $item) {
$igtv = $this->mediaHydrator->hydrateMediaFromProfile($item->node);
$this->profile->addIGTV($igtv);
Expand Down
3 changes: 3 additions & 0 deletions tests/Auth/Checkpoint/ImapClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class ImapClientTest extends TestCase
{
public function testSetUpCredentials()
{
if(!extension_loaded('imap')) {
$this->markTestSkipped('IMAP extension not loaded');
}
$credentials = new ImapClient('imap.google.com', 'login', 'password');
$this->assertSame('imap.google.com', $credentials->getServer());
$this->assertSame('login', $credentials->getLogin());
Expand Down
9 changes: 4 additions & 5 deletions tests/ProfileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ public function testValidApiCalls()
$this->assertFalse($profile->isPrivate());
$this->assertTrue($profile->isVerified());
$this->assertSame(419, $profile->getMediaCount());
$this->assertTrue($profile->hasMoreMedias());
$this->assertCount(12, $profile->getMedias());
$this->assertSame(null, $profile->getMedias()[0]->getAccessibilityCaption());
$this->assertFalse($profile->hasMoreMedias());
$this->assertCount(0, $profile->getMedias());

$this->assertSame(1518284433, $profile->__serialize()['id']);
$this->assertSame('robertdowneyjr', $profile->__serialize()['userName']);
Expand All @@ -66,8 +65,8 @@ public function testValidApiCalls()
$this->assertFalse($profile->__serialize()['private']);
$this->assertTrue($profile->__serialize()['verified']);
$this->assertSame(419, $profile->__serialize()['mediaCount']);
$this->assertTrue($profile->__serialize()['hasMoreMedias']);
$this->assertCount(12, $profile->__serialize()['medias']);
$this->assertFalse($profile->__serialize()['hasMoreMedias']);
$this->assertCount(0, $profile->__serialize()['medias']);

$profile = $api->getMoreMedias($profile);
$media = $profile->getMedias()[0];
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/igtv.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/fixtures/profile.json

Large diffs are not rendered by default.

Loading