Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/pgrimaud/instagram-user-feed

This is a scrapper to easily fetch any feed and interact with Instagram (like, follow, etc.) without OAuth for PHP.
https://github.com/pgrimaud/instagram-user-feed

checkpoint-challenge-bypass igtv instagram instagram-api instagram-client instagram-crawler instagram-feed instagram-scraper instagram-sdk packagist php php7 php8 reels

Last synced: 29 days ago
JSON representation

This is a scrapper to easily fetch any feed and interact with Instagram (like, follow, etc.) without OAuth for PHP.

Awesome Lists containing this project

README

        

# Instagram user feed PHP
[![Build Status](https://github.com/pgrimaud/instagram-user-feed/actions/workflows/main.yaml/badge.svg)](https://github.com/pgrimaud/instagram-user-feed/actions)
[![Packagist](https://img.shields.io/badge/packagist-install-brightgreen.svg)](https://packagist.org/packages/pgrimaud/instagram-user-feed)
[![Coverage Status](https://coveralls.io/repos/github/pgrimaud/instagram-user-feed/badge.svg?branch=master)](https://coveralls.io/github/pgrimaud/instagram-user-feed?branch=master)

[![Minimum PHP Version](https://img.shields.io/packagist/php-v/pgrimaud/instagram-user-feed.svg?maxAge=3600)](https://packagist.org/packages/pgrimaud/instagram-user-feed)
[![Last version](https://img.shields.io/packagist/v/pgrimaud/instagram-user-feed?maxAge=3600)](https://packagist.org/packages/pgrimaud/instagram-user-feed)
[![Total Downloads](https://poser.pugx.org/pgrimaud/instagram-user-feed/downloads)](https://packagist.org/packages/pgrimaud/instagram-user-feed)

[![All Contributors](https://img.shields.io/badge/all_contributors-31-orange.svg)](#contributors)

> **Warning**
> 2023-12-31 - Version 7.0.0 will drop support for PHP < 8.2

> **Warning**
> 2022-11-09 - Instagram changed his DOM AGAIN... Please update to this version 6.16.4

> **Warning**
> 2022-06-01 - Instagram changed his DOM content and profile data loading. Please update to this version 6.15.0

## Information
Easily fetch any Instagram feed and more without OAuth for PHP.

If you like or use this package, please share your love by starring this repository, follow [@pgrimaud](https://github.com/pgrimaud) or [become a sponsor](https://github.com/sponsors/pgrimaud). πŸ™πŸ’“

## Features

- Fetch profile data of user
- Fetch medias of user
- Fetch stories of user
- Fetch highlights stories of user
- Fetch detailed post of user
- Fetch feed of followers
- Fetch feed of followings
- Follow or unfollow users
- Like or unlike posts
- Fetch posts of hashtag
- Fetch comments of a post
- Fetch live-streaming info
- Fetch Reels
- Fetch IGTV
- Fetch medias where a user has been tagged on
- Fetch HD profile picture
- Post a message to a media
- **NEW: Login with cookies πŸŽ‰**
- **NEW: Fetch connected user timeline πŸŽ‰**

This version can retrieve **ANY** Instagram feed using **web scraping**.

- [Installation](#installation)
- [Usage](#usage)
- [Medias paginate](#paginate)
- [Stories](#stories)
- [Examples](https://github.com/pgrimaud/instagram-user-feed/tree/master/examples)

**⚠️ Version ^5.0 is no more maintained. ⚠️**

# Installation

```
composer require pgrimaud/instagram-user-feed
```

# Changelog

**v7.0.0** - 2023-12-31:

- Drop support for PHP < 8.2

**v6.16.6** - 2023-12-31:

- Add support for Symfony 7
- Fix login error "Unable to extract JSON data" ([n1crask](https://github.com/n1crask))

**v6.16.5** - 2023-12-24:

- 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 ([cookieguru](https://github.com/cookieguru))
- Same for IGTV ([cookieguru](https://github.com/cookieguru))
- Fix imap_delete second parameter ([deepvision7](https://github.com/deepvision7))

**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)) πŸŽ‰.
- Fetch connected user timeline. Thanks to [nsmle](https://github.com/nsmle) (example [here](https://github.com/pgrimaud/instagram-user-feed/blob/master/examples/timeline.php)) πŸŽ‰.
- Add full support for Symfony 6
- Add checks on missing properties to avoid errors

**v6.15** - 2022-06-02:

- ⚠️ ⚠️ Fix profile endpoint. Please update to this last version!

**v6.12** - 2021-09-20:

- Add method to post message on a media (example [here](https://github.com/pgrimaud/instagram-user-feed/blob/master/examples/post-comment.php)) πŸŽ‰.
- Add method to get HD profile picture (example [here](https://github.com/pgrimaud/instagram-user-feed/blob/master/examples/profile-alternative.php)) πŸŽ‰.

**v6.11** - 2021-09-13:

- Add method to fetch medias where a user has been tagged on (example [here](https://github.com/pgrimaud/instagram-user-feed/blob/master/examples/tagged-medias.php)) πŸŽ‰.

**v6.10** - 2021-09-03:

- Add method to fetch IGTV (example [here](https://github.com/pgrimaud/instagram-user-feed/blob/master/examples/igtv.php)) πŸŽ‰.
- Add method to fetch Reels (example [here](https://github.com/pgrimaud/instagram-user-feed/blob/master/examples/reels.php)) πŸŽ‰.
- Split dirty tests in multiple files.

**v6.9** - 2021-09-02:

- Add method to fetch Instagram live-streaming info. Thanks to [David-Kurniawan](https://github.com/David-Kurniawan)
- Minor fixes.

**[v6.8](#version-68-strict-origin-when-cross-origin)** - 2021-07-08:

- Add video url in media feed. Thanks to [@Nispeon](https://github.com/Nispeon)
- Add helper to download media (ref to [#205 : strict-origin-when-cross-origin](https://github.com/pgrimaud/instagram-user-feed/issues/205)). Thanks to [@Nispeon](https://github.com/Nispeon)
- Minor changes and improvements.

**v6.7** - 2021-01-31:

- New feature: get **post** of **hashtag**.
- New feature: get **comments** of **post**.
- Add support for PHP 8.
- Minor changes and improvements.

**v6.6** - 2020-10-06:

- New feature: **like** and **unlike** posts.
- Retrieval **#hashtags** and **@mentions** from stories.
- Minor changes and improvements.

**v6.5** - 2020-09-14:

- New feature: follow and unfollow users. Thanks to [@David-Kurniawan](https://github.com/David-Kurniawan))
- Minor fixes.

**v6.4** - 2020-08-30:

- New feature: fetch followers and followings feeds. Thanks to [@David-Kurniawan](https://github.com/David-Kurniawan))
- Minor improvements.

**[v6.3](#version-63-checkpoint-challenge-bypass)** -2020-07-03:

- Add checkpoint challenge bypass using IMAP configuration.

**v6.2** - 2020-06-01:

- Improve medias crawling && cache constraints.

**v6.1** - 2020-05-21:

- New feature: Fetch stories and highlights stories.

**[v6.0](#version-60-login)** - 2020-05-20

- Please upgrade from ^5.0 for cookies session stability.

## Version ^6.8: strict-origin-when-cross-origin

Facebook added a new CORS policy, and you can't display the data directly.

You can now download media on your storage or server to serve it directly on your website. You can find an example [here](https://github.com/pgrimaud/instagram-user-feed/blob/master/examples/medias-download.php).

**Example:**

```php
login('username', 'password'); // mandatory
$profile = $api->getProfile('robertdowneyjr');

echo $profile->getUserName(); // robertdowneyjr

echo $profile->getFullName(); // Robert Downey Jr. Official
```

### Basic usage :

```php
login('username', 'password');

$profile = $api->getProfile('robertdowneyjr');

print_r($profile);
```

```php
Instagram\Hydrator\Component\Feed Object
(
[id] => 1518284433
[userName] => robertdowneyjr
[fullName] => Robert Downey Jr. Official
[biography] => @officialfootprintcoalition @coreresponse
[followers] => 46382057
[following] => 50
[profilePicture] => https://scontent-cdt1-1.cdninstagram.com/v/t51.2885-19/s320x320/72702032_542075739927421_3928117925747097600_n.jpg?_nc_ht=scontent-cdt1-1.cdninstagram.com&_nc_ohc=h2zGWoshNjUAX9ze3jb&oh=cf6441cfc3f258da3bf4cfef29686c7d&oe=5EEEC338
[externalUrl] => http://coreresponse.org/covid19
[private] =>
[verified] => 1
[mediaCount] => 453
(
[0] => Instagram\Model\InstagramMedia Object
(
[id] => 2307655221969878423
[typeName] => GraphImage
[height] => 1350
[width] => 1080
[thumbnailSrc] => https://scontent-cdt1-1.cdninstagram.com/v/t51.2885-15/sh0.08/e35/c0.180.1440.1440a/s640x640/96225997_178111910111734_5886065436455432375_n.jpg?_nc_ht=scontent-cdt1-1.cdninstagram.com&_nc_cat=1&_nc_ohc=GqcYpSEbz8gAX_GF1Ep&oh=1b293215142d407faca46a2fd28eab71&oe=5EF0EBDF
[link] => https://www.instagram.com/p/CAGcDKplv2X/
[date] => DateTime Object
(
[date] => 2020-05-12 22:06:01.000000
[timezone_type] => 3
[timezone] => Europe/Paris
)

[displaySrc] => https://scontent-cdt1-1.cdninstagram.com/v/t51.2885-15/e35/p1080x1080/96225997_178111910111734_5886065436455432375_n.jpg?_nc_ht=scontent-cdt1-1.cdninstagram.com&_nc_cat=1&_nc_ohc=GqcYpSEbz8gAX_GF1Ep&oh=6c19ddef96fdc07d7926b05e36cb2bed&oe=5EEED2CE
[caption] => The sweetest things are worth waiting for…Susan and I are producing a @Netflix original series, Sweet Tooth, based on the comic by @Jefflemire. Can’t wait to share it with you all. 🦌 πŸ‘¦ @NXonNetflix @warnerbrostv #SweetTooth
[comments] => 3308
[likes] => 687988
[thumbnails] => Array
(
[0] => stdClass Object
(
[src] => https://scontent-cdt1-1.cdninstagram.com/v/t51.2885-15/e35/c0.180.1440.1440a/s150x150/96225997_178111910111734_5886065436455432375_n.jpg?_nc_ht=scontent-cdt1-1.cdninstagram.com&_nc_cat=1&_nc_ohc=GqcYpSEbz8gAX_GF1Ep&oh=24b300201afc0e0c82166c6288e0ed5b&oe=5EF00196
[config_width] => 150
[config_height] => 150
)

[1] => stdClass Object
(
[src] => https://scontent-cdt1-1.cdninstagram.com/v/t51.2885-15/e35/c0.180.1440.1440a/s240x240/96225997_178111910111734_5886065436455432375_n.jpg?_nc_ht=scontent-cdt1-1.cdninstagram.com&_nc_cat=1&_nc_ohc=GqcYpSEbz8gAX_GF1Ep&oh=203d0a3d01d77a2978739c96eb67e607&oe=5EEF6DE0
[config_width] => 240
[config_height] => 240
)

[2] => stdClass Object
(
[src] => https://scontent-cdt1-1.cdninstagram.com/v/t51.2885-15/e35/c0.180.1440.1440a/s320x320/96225997_178111910111734_5886065436455432375_n.jpg?_nc_ht=scontent-cdt1-1.cdninstagram.com&_nc_cat=1&_nc_ohc=GqcYpSEbz8gAX_GF1Ep&oh=7b9cee64460e1c9c501e59621e6ccfb2&oe=5EF18BE6
[config_width] => 320
[config_height] => 320
)

[3] => stdClass Object
(
[src] => https://scontent-cdt1-1.cdninstagram.com/v/t51.2885-15/e35/c0.180.1440.1440a/s480x480/96225997_178111910111734_5886065436455432375_n.jpg?_nc_ht=scontent-cdt1-1.cdninstagram.com&_nc_cat=1&_nc_ohc=GqcYpSEbz8gAX_GF1Ep&oh=f3d8c31eca2d3c3ab6653b3ed3ebe4f4&oe=5EEFEAC0
[config_width] => 480
[config_height] => 480
)

[4] => stdClass Object
(
[src] => https://scontent-cdt1-1.cdninstagram.com/v/t51.2885-15/sh0.08/e35/c0.180.1440.1440a/s640x640/96225997_178111910111734_5886065436455432375_n.jpg?_nc_ht=scontent-cdt1-1.cdninstagram.com&_nc_cat=1&_nc_ohc=GqcYpSEbz8gAX_GF1Ep&oh=1b293215142d407faca46a2fd28eab71&oe=5EF0EBDF
[config_width] => 640
[config_height] => 640
)

)

[location] =>
[video] =>
[videoViewCount] => 0
)
...

[endCursor:Instagram\Model\InstagramProfile:private] => QVFEblBGclVyOEtCMmRLZkVxUUdVbmhsYXNMZmMmplNWtZRkJnRnZOSUdMM1BDRmt3ZA==
)

```

## Paginate
If you want to use paginate on medias, just call `getMoreMedias` method.

```php
login($credentials->getLogin(), $credentials->getPassword());

$profile = $api->getProfile('twhiddleston');

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());
```

## Stories

```php
login('username', 'password'); // mandatory

$profile = $api->getProfile('starwars'); // we need instagram username
sleep(1);
$feedStories = $api->getStories($profile->getId());

$stories = $feedStories->getStories();

print_r($stories);
```

# Contributors

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):



Pierre Grimaud
Pierre Grimaud

πŸ’»
Jan Γ–stlund
Jan Γ–stlund

πŸ’»
Tim Bond
Tim Bond

πŸ’»
Dlinny
Dlinny

πŸ›
RenΓ©
RenΓ©

πŸ›
ikiselev1989
ikiselev1989

πŸ›
Pezhvak
Pezhvak

πŸ’»


David Greminger
David Greminger

πŸ’»
Nana YAMANE
Nana YAMANE

πŸ’»
David Kurniawan
David Kurniawan

πŸ’»
gtapps
gtapps

πŸ’»
Chun-Sheng, Li
Chun-Sheng, Li

⚠️
schelmo
schelmo

πŸ’»
Mojtaba
Mojtaba

πŸ’»


Georgy Gusev
Georgy Gusev

πŸ’»
Jibran Ijaz
Jibran Ijaz

πŸ’»
Julien Cousin-Alliot
Julien Cousin-Alliot

πŸ’»
n-richaud
n-richaud

πŸ›
Dmitry Afonin
Dmitry Afonin

πŸ’»
Andrei Firoiu
Andrei Firoiu

πŸ›
Fiki Pratama
Fiki Pratama

πŸ’»


Carl
Carl

πŸ›
Peter Kampjes
Peter Kampjes

πŸ’»
Bob Brown
Bob Brown

πŸ“–
nagajoomlapro
nagajoomlapro

πŸ’»
cleveng
cleveng

πŸ’»
BMRG14
BMRG14

πŸ’»
Sinan Portakal
Sinan Portakal

πŸ’»


deepvision7
deepvision7

πŸ’»
Yusuf Γ–zdemir
Yusuf Γ–zdemir

πŸ’»
Kadir Melih Can
Kadir Melih Can

πŸ’»

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

# Feedback

You found a bug? You need a new feature? You can [create an issue](https://github.com/pgrimaud/instagram-user-feed/issues) if needed or contact me on [Twitter](https://twitter.com/pgrimaud_).

# License

Licensed under the terms of the MIT License.