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

getMedias return empty array #390

Open
nkjha opened this issue Dec 21, 2024 · 4 comments
Open

getMedias return empty array #390

nkjha opened this issue Dec 21, 2024 · 4 comments
Assignees
Labels
need-investigations Need investigations to classify

Comments

@nkjha
Copy link

nkjha commented Dec 21, 2024

Version(s) affected: x.y.z

Description
A clear and concise description of the problem.

How to reproduce
Code and/or config needed to reproduce the problem.

Possible Solution
Optional: only if you have suggestions on a fix/reason for the bug

Additional context
Optional: any other context about the problem: log messages, screenshots, etc.

@nkjha nkjha added the need-investigations Need investigations to classify label Dec 21, 2024
@nkjha
Copy link
Author

nkjha commented Dec 21, 2024

This is my medias.php code, I am getting empty array: <?php

declare(strict_types=1);

use Instagram\Api;
use Instagram\Exception\InstagramException;

use Psr\Cache\CacheException;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

require realpath(dirname(FILE)) . '/../vendor/autoload.php';
$credentials = include_once realpath(dirname(FILE)) . '/credentials.php';

$cachePool = new FilesystemAdapter('Instagram', 0, DIR . '/../cache');

try {
$api = new Api($cachePool);
$api->login($credentials->getLogin(), $credentials->getPassword());

$profile = $api->getProfile('cagspune');
print_r($profile->getMedias()); // 12 first medias

do {
    $profile = $api->getMoreMedias($profile);
    print_r($profile->getMedias()); // 12 more medias

    // avoid 429 Rate limit from Instagram
    sleep(1);
} while ($profile->hasMoreMedias());

/* printMedias($profile->getMedias());

do {
    $profile = $api->getMoreMedias($profile);
    printMedias($profile->getMedias());
   
    // Or with profile id
    //$profile = $api->getMoreMediasWithProfileId(3504244670);
    //printMedias($profile->getMedias());

    // avoid 429 Rate limit from Instagram
    sleep(1);
} while ($profile->hasMoreMedias());*/

} catch (InstagramException $e) {
print_r($e->getMessage());
} catch (CacheException $e) {
print_r($e->getMessage());
}

function printMedias(array $medias)
{
foreach ($medias 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\n";
}
}

@nkjha nkjha changed the title getMedias empty arrat getMedias return empty array Dec 21, 2024
@Ahtnezev
Copy link

I also have this problem but with ->getMoreMedias($profile), it throws a syntax error.
v. 7.0.0
php 8.3.11
Laravel 11

@mohamadShahkhajeh
Copy link

I also have this problem but with ->getMoreMedias($profile), it throws a syntax error. v. 7.0.0 php 8.3.11 Laravel 11

hi
i also have this problem and it return me the "syntax error" .
how can we use the medias of special accounts ?
@pgrimaud

@sermagnus
Copy link

I also have this problem but with ->getMoreMedias($profile), it throws a syntax error. v. 7.0.0 php 8.3.11 Laravel 11

hi i also have this problem and it return me the "syntax error" . how can we use the medias of special accounts ? @pgrimaud

As I wrote in #389, it seems to be an issue related to special characters in the JSON reply from Instagram.
#389 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need-investigations Need investigations to classify
Projects
None yet
Development

No branches or pull requests

5 participants