Is there a way to pull an instagram feed with PHP without logging in?

前端 未结 3 1634
迷失自我
迷失自我 2021-02-04 19:40

It seems that this solution no longer works -

How to get a user's Instagram feed

The new API requires an access token which is dynamically assigned after pas

3条回答
  •  悲哀的现实
    2021-02-04 20:05

    Try this php library: https://github.com/postaddictme/instagram-php-scraper

    And here is example (https://github.com/postaddictme/instagram-php-scraper/blob/master/examples/getAccountMediasByUsername.php):

    getMedias('kevin', 25);
    // Let's look at $media
    $media = $medias[0];
    echo "Media info:\n";
    echo "Id: {$media->getId()}\n";
    echo "Shotrcode: {$media->getShortCode()}\n";
    echo "Created at: {$media->getCreatedTime()}\n";
    echo "Caption: {$media->getCaption()}\n";
    echo "Number of comments: {$media->getCommentsCount()}";
    echo "Number of likes: {$media->getLikesCount()}";
    echo "Get link: {$media->getLink()}";
    echo "High resolution image: {$media->getImageHighResolutionUrl()}";
    echo "Media type (video or image): {$media->getType()}";
    $account = $media->getOwner();
    echo "Account info:\n";
    echo "Id: {$account->getId()}\n";
    echo "Username: {$account->getUsername()}\n";
    echo "Full name: {$account->getFullName()}\n";
    echo "Profile pic url: {$account->getProfilePicUrl()}\n";
    // If account private you should be subscribed and after auth it will be available
    $instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', 'path/to/cache/folder');
    $instagram->login();
    $medias = $instagram->getMedias('private_account', 100);
    

提交回复
热议问题