-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from postaddictme/master
Updating fork
- Loading branch information
Showing
37 changed files
with
2,728 additions
and
663 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ composer.phar | |
composer.lock | ||
.DS_Store | ||
phpunit.phar | ||
index.php | ||
tests/sessions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,180 +1,46 @@ | ||
# instagram-php-scraper | ||
# Usage | ||
# Instagram PHP Scrapper | ||
This library based on Instagram web version. We develop it because nowadays it is hard to get approved Instagram application. | ||
The purpose support every feature that web desktop and mobile version support. | ||
|
||
`composer require raiym/instagram-php-scraper` | ||
|
||
|
||
```php | ||
use InstagramScraper\Instagram; | ||
|
||
``` | ||
|
||
### Get account info | ||
```php | ||
$account = Instagram::getAccount('kevin'); | ||
/* | ||
Available properties: | ||
$username; | ||
$followsCount; | ||
$followedByCount; | ||
$profilePicUrl; | ||
$id; | ||
$biography; | ||
$fullName; | ||
$mediaCount; | ||
$isPrivate; | ||
$externalUrl; | ||
*/ | ||
echo $account->followedByCount; | ||
``` | ||
### Get account info by userId | ||
## Code Example | ||
```php | ||
$account = Instagram::getAccountById(193886659); | ||
echo $account->username; | ||
$instagram = Instagram::withCredentials('username', 'password'); | ||
$instagram->login(); | ||
$account = $instagram->getAccountById(3); | ||
echo $account->getUsername(); | ||
``` | ||
|
||
### Search users by username | ||
Some methods does not require auth: | ||
```php | ||
$users = Instagram::searchAccountsByUsername('durov'); | ||
echo '<pre>'; | ||
echo json_encode($users); | ||
echo '</pre><br/>'; | ||
$instagram = new Instagram(); | ||
$nonPrivateAccountMedias = $instagram->getMedias('kevin'); | ||
echo $nonPrivateAccountMedias[0]->getLink(); | ||
``` | ||
If you use auth it is recommended to cash user session, in this case you don't need run `$instagram->login()` method every time your program runs: | ||
|
||
### Get account medias | ||
```php | ||
$medias = Instagram::getMedias('kevin', 150); | ||
|
||
/* | ||
Available properties: | ||
$id; | ||
$createdTime; | ||
$type; | ||
$link; | ||
$imageLowResolutionUrl; | ||
$imageThumbnailUrl; | ||
$imageStandardResolutionUrl; | ||
$imageHighResolutionUrl; | ||
$caption; | ||
$captionIsEdited; | ||
$isAd; | ||
$videoLowResolutionUrl; | ||
$videoStandardResolutionUrl; | ||
$videoLowBandwidthUrl; | ||
$videoViews; | ||
$code; | ||
$owner; | ||
$ownerId; | ||
$likesCount; | ||
$locationId; | ||
$locationName; | ||
$commentsCount; | ||
|
||
*/ | ||
echo $medias[0]->imageHighResolutionUrl; | ||
echo $medias[0]->caption; | ||
|
||
$instagram = Instagram::withCredentials('username', 'password', '/path/to/cache/folder/'); | ||
$instagram->login(); // will use cached session if you can force login $instagram->login(true) | ||
$account = $instagram->getAccountById(3); | ||
echo $account->getUsername(); | ||
``` | ||
|
||
### Paginate medias | ||
```php | ||
$result = Instagram::getPaginateMedias('kevin'); | ||
$medias = $result['medias'] | ||
## Installation | ||
|
||
if($result['hasNextPage'] === true) { | ||
$result = Instagram::getPaginateMedias('kevin', $result['maxId']); | ||
$medias = array_merge($medias, $result['medias']); | ||
} | ||
### Using composer | ||
|
||
echo json_encode($medias); | ||
```sh | ||
composer.phar require raiym/instagram-php-scraper | ||
``` | ||
|
||
### Get media by code | ||
```php | ||
$media = Instagram::getMediaByCode('BDs9iwfL7XA'); | ||
or | ||
```sh | ||
composer require raiym/instagram-php-scraper | ||
``` | ||
|
||
### Get media by url | ||
```php | ||
$media = Instagram::getMediaByUrl('https://www.instagram.com/p/BDs9iwfL7XA/'); | ||
echo $media->owner->username; | ||
``` | ||
|
||
### Get media by id | ||
```php | ||
$media = Instagram::getMediaById(1042815830884781756); | ||
``` | ||
|
||
### Search medias by tag name | ||
```php | ||
$medias = Instagram::getMediasByTag('zara', 30); | ||
echo json_encode($medias); | ||
``` | ||
|
||
### Paginate medias by tag name | ||
```php | ||
$result = Instagram::getPaginateMediasByTag('zara'); | ||
$medias = $result['medias'] | ||
|
||
if($result['hasNextPage'] === true) { | ||
$result = Instagram::getPaginateMediasByTag('zara', $result['maxId']); | ||
$medias = array_merge($medias, $result['medias']); | ||
} | ||
|
||
echo json_encode($medias); | ||
``` | ||
### If you don't have composer | ||
You can download it [here](https://getcomposer.org/download/). | ||
|
||
### Get top medias by tag name | ||
```php | ||
$medias = Instagram::getTopMediasByTagName('durov'); | ||
``` | ||
|
||
### Get media by id | ||
```php | ||
$media = Instagram::getMediaById(1270593720437182847) | ||
``` | ||
|
||
### Convert media id to shortcode | ||
```php | ||
echo 'CODE: ' . Media::getCodeFromId('1270593720437182847_3'); | ||
// OR | ||
echo 'CODE: ' . Media::getCodeFromId('1270593720437182847'); | ||
// OR | ||
echo 'CODE: ' . Media::getCodeFromId(1270593720437182847); | ||
// CODE: BGiDkHAgBF_ | ||
// So you can do like this: instagram.com/p/BGiDkHAgBF_ | ||
``` | ||
|
||
### Convert shortcode to media id | ||
```php | ||
echo 'Media id: ' . Media::getIdFromCode('BGiDkHAgBF_'); | ||
// Media id: 1270593720437182847 | ||
``` | ||
|
||
### Get media comments by shortcode | ||
```php | ||
$comments = Instagram::getMediaCommentsByCode('BG3Iz-No1IZ', 8000); | ||
``` | ||
|
||
### Get media comments by id | ||
```php | ||
$comments = Instagram::getMediaCommentsById('1130748710921700586', 10000) | ||
``` | ||
|
||
### Get location id | ||
```php | ||
$medias = Instagram::getLocationById(1); | ||
``` | ||
|
||
### Get location top medias by location id | ||
```php | ||
$medias = Instagram::getLocationTopMediasById(1); | ||
``` | ||
|
||
### Get location medias by location id | ||
```php | ||
$medias = Instagram::getLocationMediasById(1); | ||
``` | ||
## Examples | ||
See examples [here](https://github.com/postaddictme/instagram-php-scraper/tree/master/examples). | ||
|
||
### Other | ||
## Other | ||
Java library: https://github.com/postaddictme/instagram-java-scraper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
use InstagramScraper\Model\Media; | ||
|
||
|
||
echo 'Shortcode: ' . Media::getCodeFromId('1270593720437182847_3') . "\n"; // Shortcode: BGiDkHAgBF_ | ||
echo 'Shortcode: ' . Media::getCodeFromId('1270593720437182847') . "\n"; // Shortcode: BGiDkHAgBF_ | ||
|
||
// And you can get link to media: instagram.com/p/BGiDkHAgBF_ | ||
|
||
echo 'Media id: ' . Media::getIdFromCode('BGiDkHAgBF_'); // Media id: 1270593720437182847 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', '/path/to/cache/folder'); | ||
$instagram->login(); | ||
$account = $instagram->getAccountById('3'); | ||
|
||
// Available fields | ||
echo "Account info:\n"; | ||
echo "Id: {$account->getId()}\n"; | ||
echo "Username: {$account->getUsername()}\n"; | ||
echo "Full name: {$account->getFullName()}\n"; | ||
echo "Biography: {$account->getBiography()}\n"; | ||
echo "Profile picture url: {$account->getProfilePicUrl()}\n"; | ||
echo "External link: {$account->getExternalUrl()}\n"; | ||
echo "Number of published posts: {$account->getMediaCount()}\n"; | ||
echo "Number of followers: {$account->getFollowsCount()}\n"; | ||
echo "Number of follows: {$account->getFollowedByCount()}\n"; | ||
echo "Is private: {$account->isPrivate()}\n"; | ||
echo "Is verified: {$account->isVerified()}\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
// If account is public you can query Instagram without auth | ||
|
||
$instagram = new \InstagramScraper\Instagram(); | ||
|
||
// For getting information about account you don't need to auth: | ||
|
||
$account = $instagram->getAccount('kevin'); | ||
|
||
// Available fields | ||
echo "Account info:\n"; | ||
echo "Id: {$account->getId()}\n"; | ||
echo "Username: {$account->getUsername()}\n"; | ||
echo "Full name: {$account->getFullName()}\n"; | ||
echo "Biography: {$account->getBiography()}\n"; | ||
echo "Profile picture url: {$account->getProfilePicUrl()}\n"; | ||
echo "External link: {$account->getExternalUrl()}\n"; | ||
echo "Number of published posts: {$account->getMediaCount()}\n"; | ||
echo "Number of followers: {$account->getFollowsCount()}\n"; | ||
echo "Number of follows: {$account->getFollowedByCount()}\n"; | ||
echo "Is private: {$account->isPrivate()}\n"; | ||
echo "Is verified: {$account->isVerified()}\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', 'path/to/cache/folder'); | ||
$instagram->login(); | ||
sleep(2); // Delay to mimic user | ||
|
||
$username = 'kevin'; | ||
$followers = []; | ||
$account = $instagram->getAccount($username); | ||
sleep(1); | ||
$followers = $instagram->getFollowers($account->getId(), 1000, 100, true); // Get 1000 followers of 'kevin', 100 a time with random delay between requests | ||
echo '<pre>' . json_encode($followers, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . '</pre>'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
// If account is public you can query Instagram without auth | ||
|
||
$instagram = new \InstagramScraper\Instagram(); | ||
$medias = $instagram->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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', '/path/to/cache/folder'); | ||
$instagram->login(); | ||
|
||
$medias = $instagram->getCurrentTopMediasByLocationId('1'); | ||
$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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', '/path/to/cache/folder'); | ||
$instagram->login(); | ||
|
||
$medias = $instagram->getCurrentTopMediasByTagName('youneverknow'); | ||
$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"; |
Oops, something went wrong.