Skip to content

Commit

Permalink
Do not hydrate media or IGTV loaded with profile data (#362)
Browse files Browse the repository at this point in the history
* Mark IMAP client test as skipped when IMAP extension is not loaded

This prevents having the test suite fail on platforms when the extension
is not loaded.  The test is marked as skipped so the developer knows
that the full test suite was not run

* Add a convenience script to run unit tests with "composer test"

* Do not hydrate media or IGTV loaded with profile data

Instagram no longer reliably returns medias or IGTVs with the call to
get profile information.  Instead, the user must explicitly make a call
to `\Instagram\Api::getMoreMedias` in order to fetch medias or to
`getMoreIgtvs` to fetch IGTVs
  • Loading branch information
cookieguru committed Dec 23, 2023
1 parent d420ad2 commit 3ece0a4
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 9 deletions.
7 changes: 7 additions & 0 deletions README.md
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
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
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
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
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
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.

0 comments on commit 3ece0a4

Please sign in to comment.