Skip to content

Commit

Permalink
Merge remote-tracking branch 'github/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Geolim4 committed Nov 6, 2017
2 parents 768999b + 3f8f166 commit 374833f
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 72 deletions.
69 changes: 4 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ echo $account->getUsername();

### Using composer

```sh
composer.phar require raiym/instagram-php-scraper
```
or
```sh
composer require raiym/instagram-php-scraper
```
Expand All @@ -38,70 +42,5 @@ You can download it [here](https://getcomposer.org/download/).
## Examples
See examples [here](https://github.com/postaddictme/instagram-php-scraper/tree/master/examples).



### Some of following examples outdated (fixing it)

if you need to get medias by tags or locations:
```php
$instagram = Instagram::withCredentials('username', 'password');
$instagram->login();
// And then you will be able to query instagram with newly updated methods. (Notice that these methods are not static anymore)

$medias $instagram->getLocationTopMediasById(1)
$medias = $instagram->getLocationMediasById(1);
$medias = $instagram->getTopMediasByTagName('hello');
```

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

### Get top medias by tag name
```php
$medias = Instagram::getTopMediasByTagName('durov');
```
### 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 location top medias by location id
```php
$medias = Instagram::getLocationTopMediasById(1);
```

### Get location medias by location id
```php
$medias = Instagram::getLocationMediasById(1);
```

## Other
Java library: https://github.com/postaddictme/instagram-java-scraper
12 changes: 12 additions & 0 deletions examples/convertShortcode.php
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
24 changes: 24 additions & 0 deletions examples/getCurrentTopMediasByLocationId.php
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";
24 changes: 24 additions & 0 deletions examples/getCurrentTopMediasByTagName.php
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";
24 changes: 24 additions & 0 deletions examples/getMediasByLocationId.php
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->getMediasByLocationId('1', 20);
$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";
24 changes: 24 additions & 0 deletions examples/getMediasByTag.php
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->getMediasByTag('youneverknow', 20);
$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";
15 changes: 15 additions & 0 deletions examples/getPaginateMediasByTag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
require __DIR__ . '/../vendor/autoload.php';

$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', '/path/to/cache/folder');
$instagram->login();

$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);
15 changes: 8 additions & 7 deletions src/InstagramScraper/Instagram.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,9 @@ public function getAccount($username)
* @param string $tag
* @param int $count
* @param string $maxId
* @param string $minTimestamp
*
* @return array
* @return Media[]
* @throws InstagramException
*/
public function getMediasByTag($tag, $count = 12, $maxId = '', $minTimestamp = null)
Expand Down Expand Up @@ -593,11 +594,11 @@ public function getPaginateMediasByTag($tag, $maxId = '')
/**
* @param $tagName
*
* @return array
* @return Media[]
* @throws InstagramException
* @throws InstagramNotFoundException
*/
public function getTopMediasByTagName($tagName)
public function getCurrentTopMediasByTagName($tagName)
{
$response = Request::get(Endpoints::getMediasJsonByTagLink($tagName, ''),
$this->generateHeaders($this->userSession));
Expand All @@ -620,11 +621,11 @@ public function getTopMediasByTagName($tagName)
/**
* @param $facebookLocationId
*
* @return array
* @return Media[]
* @throws InstagramException
* @throws InstagramNotFoundException
*/
public function getLocationTopMediasById($facebookLocationId)
public function getCurrentTopMediasByLocationId($facebookLocationId)
{
$response = Request::get(Endpoints::getMediasJsonByLocationIdLink($facebookLocationId),
$this->generateHeaders($this->userSession));
Expand All @@ -650,10 +651,10 @@ public function getLocationTopMediasById($facebookLocationId)
* @param int $quantity
* @param string $offset
*
* @return array
* @return Media[]
* @throws InstagramException
*/
public function getLocationMediasById($facebookLocationId, $quantity = 12, $offset = '')
public function getMediasByLocationId($facebookLocationId, $quantity = 12, $offset = '')
{
$index = 0;
$medias = [];
Expand Down

0 comments on commit 374833f

Please sign in to comment.