Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrimaud committed Mar 16, 2018
1 parent b236f6e commit 3910319
Show file tree
Hide file tree
Showing 3 changed files with 214 additions and 36 deletions.
180 changes: 158 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,78 @@ composer require pgrimaud/instagram-user-feed

## Warning

**Due to changes of the Instagram API, you have to upgrade to version ^2.0.**

*Edit 2018-03-16 : Pagination seems to be broken - waiting for a fix or fallback*
**2018-03-16 : Due to changes of the Instagram API, you must upgrade to version ^2.1**

## Usage

### Retrieve user data only

```php
$api = new Api();

// For user data, userName is mandatory!
$api->setUserName('pgrimaud');

// for paginate
//$api->setMaxId(1676900800864278214);
$api->retrieveUserData(true);

$feed = $api->getFeed();

print_r($feed);

```

```
```php
Instagram\Hydrator\Feed Object
(
[id] => 184263228
[userName] => pgrimaud
[fullName] => Pierre G
[biography] => Gladiator retired - ESGI 14'
[isVerified] =>
[followers] => 336
[following] => 110
[profilePicture] => https://scontent-cdg2-1.cdninstagram.com/t51.2885-19/10483606_1498368640396196_604136733_a.jpg
[profilePictureHd] => https://scontent-cdg2-1.cdninstagram.com/t51.2885-19/10483606_1498368640396196_604136733_a.jpg
[isVerified] =>
[followers] => 337
[following] => 113
[profilePicture] => https://scontent-cdg2-1.cdninstagram.com/vp/faf7cfb2f6ea29b57d3032717d8789bf/5B34242E/t51.2885-19/10483606_1498368640396196_604136733_a.jpg
[profilePictureHd] => https://scontent-cdg2-1.cdninstagram.com/vp/faf7cfb2f6ea29b57d3032717d8789bf/5B34242E/t51.2885-19/10483606_1498368640396196_604136733_a.jpg
[externalUrl] => https://p.ier.re/
[mediaCount] => 30
[hasNextPage] =>
[medias] => Array
(
)

)
```

### Retrieve media data only

```php
$api = new Api();

// For media, userId is mandatory!
$api->setUserId(184263228);

$api->retrieveMediaData(true);

$feed = $api->getFeed();

print_r($feed);

```

```php
Instagram\Hydrator\Feed Object
(
[id] =>
[userName] =>
[fullName] =>
[biography] =>
[isVerified] =>
[followers] => 0
[following] => 0
[profilePicture] =>
[profilePictureHd] =>
[externalUrl] =>
[mediaCount] => 0
[hasNextPage] => 1
[medias] => Array
(
Expand All @@ -56,40 +95,40 @@ Instagram\Hydrator\Feed Object
[typeName] => GraphImage
[height] => 1080
[width] => 1080
[thumbnailSrc] => https://scontent-cdg2-1.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/25024600_726096737595175_9198105573181095936_n.jpg
[thumbnailSrc] => https://scontent-cdg2-1.cdninstagram.com/vp/90b54127c36ce17fefee861606db228e/5B430967/t51.2885-15/s640x640/sh0.08/e35/25024600_726096737595175_9198105573181095936_n.jpg
[thumbnailResources] => Array
(
[0] => Array
(
[src] => https://scontent-cdg2-1.cdninstagram.com/t51.2885-15/s150x150/e35/25024600_726096737595175_9198105573181095936_n.jpg
[src] => https://scontent-cdg2-1.cdninstagram.com/vp/9f2fd42a43d9a8540db2a413b6663e66/5B42D463/t51.2885-15/s150x150/e35/25024600_726096737595175_9198105573181095936_n.jpg
[width] => 150
[height] => 150
)

[1] => Array
(
[src] => https://scontent-cdg2-1.cdninstagram.com/t51.2885-15/s240x240/e35/25024600_726096737595175_9198105573181095936_n.jpg
[src] => https://scontent-cdg2-1.cdninstagram.com/vp/9a66fc162a7fece72d26c7de2fb51b01/5B32FE5C/t51.2885-15/s240x240/e35/25024600_726096737595175_9198105573181095936_n.jpg
[width] => 240
[height] => 240
)

[2] => Array
(
[src] => https://scontent-cdg2-1.cdninstagram.com/t51.2885-15/s320x320/e35/25024600_726096737595175_9198105573181095936_n.jpg
[src] => https://scontent-cdg2-1.cdninstagram.com/vp/5e70d6b0e034320a39d5357a8398484d/5B458D24/t51.2885-15/s320x320/e35/25024600_726096737595175_9198105573181095936_n.jpg
[width] => 320
[height] => 320
)

[3] => Array
(
[src] => https://scontent-cdg2-1.cdninstagram.com/t51.2885-15/s480x480/e35/25024600_726096737595175_9198105573181095936_n.jpg
[src] => https://scontent-cdg2-1.cdninstagram.com/vp/cb231fb56464841daf64935bd1551707/5B3F4AA2/t51.2885-15/s480x480/e35/25024600_726096737595175_9198105573181095936_n.jpg
[width] => 480
[height] => 480
)

[4] => Array
(
[src] => https://scontent-cdg2-1.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/25024600_726096737595175_9198105573181095936_n.jpg
[src] => https://scontent-cdg2-1.cdninstagram.com/vp/90b54127c36ce17fefee861606db228e/5B430967/t51.2885-15/s640x640/sh0.08/e35/25024600_726096737595175_9198105573181095936_n.jpg
[width] => 640
[height] => 640
)
Expand All @@ -105,16 +144,113 @@ Instagram\Hydrator\Feed Object
[timezone] => Europe/Paris
)

[displaySrc] => https://scontent-cdg2-1.cdninstagram.com/t51.2885-15/e35/25024600_726096737595175_9198105573181095936_n.jpg
[displaySrc] => https://scontent-cdg2-1.cdninstagram.com/vp/89ddb8f8c3466e7436c29d041ece4300/5B4AF306/t51.2885-15/e35/25024600_726096737595175_9198105573181095936_n.jpg
[caption] => 🎄🎅💸🙃 #casino #monaco
[comments] => 0
[likes] => 28
[likes] => 29
)
)
)
```

...
### Retrieve all data

)
```php
$api = new Api();

)
// For user data, userName is mandatory!
$api->setUserName('pgrimaud');

// For media, userId is mandatory!
$api->setUserId(184263228);

$api->retrieveUserData(true);
$api->retrieveMediaData(true);

$feed = $api->getFeed();

print_r($feed);

```

```php
Instagram\Hydrator\Feed Object
(
[id] => 184263228
[userName] => pgrimaud
[fullName] => Pierre G
[biography] => Gladiator retired - ESGI 14'
[isVerified] =>
[followers] => 337
[following] => 113
[profilePicture] => https://scontent-cdg2-1.cdninstagram.com/vp/faf7cfb2f6ea29b57d3032717d8789bf/5B34242E/t51.2885-19/10483606_1498368640396196_604136733_a.jpg
[profilePictureHd] => https://scontent-cdg2-1.cdninstagram.com/vp/faf7cfb2f6ea29b57d3032717d8789bf/5B34242E/t51.2885-19/10483606_1498368640396196_604136733_a.jpg
[externalUrl] => https://p.ier.re/
[mediaCount] => 30
[hasNextPage] => 1
[medias] => Array
(
[0] => Instagram\Hydrator\Media Object
(
[id] => 1676900800864278214
[typeName] => GraphImage
[height] => 1080
[width] => 1080
[thumbnailSrc] => https://scontent-cdg2-1.cdninstagram.com/vp/90b54127c36ce17fefee861606db228e/5B430967/t51.2885-15/s640x640/sh0.08/e35/25024600_726096737595175_9198105573181095936_n.jpg
[thumbnailResources] => Array
(
[0] => Array
(
[src] => https://scontent-cdg2-1.cdninstagram.com/vp/9f2fd42a43d9a8540db2a413b6663e66/5B42D463/t51.2885-15/s150x150/e35/25024600_726096737595175_9198105573181095936_n.jpg
[width] => 150
[height] => 150
)

[1] => Array
(
[src] => https://scontent-cdg2-1.cdninstagram.com/vp/9a66fc162a7fece72d26c7de2fb51b01/5B32FE5C/t51.2885-15/s240x240/e35/25024600_726096737595175_9198105573181095936_n.jpg
[width] => 240
[height] => 240
)

[2] => Array
(
[src] => https://scontent-cdg2-1.cdninstagram.com/vp/5e70d6b0e034320a39d5357a8398484d/5B458D24/t51.2885-15/s320x320/e35/25024600_726096737595175_9198105573181095936_n.jpg
[width] => 320
[height] => 320
)

[3] => Array
(
[src] => https://scontent-cdg2-1.cdninstagram.com/vp/cb231fb56464841daf64935bd1551707/5B3F4AA2/t51.2885-15/s480x480/e35/25024600_726096737595175_9198105573181095936_n.jpg
[width] => 480
[height] => 480
)

[4] => Array
(
[src] => https://scontent-cdg2-1.cdninstagram.com/vp/90b54127c36ce17fefee861606db228e/5B430967/t51.2885-15/s640x640/sh0.08/e35/25024600_726096737595175_9198105573181095936_n.jpg
[width] => 640
[height] => 640
)

)

[link] => https://www.instagram.com/p/BdFjGTPFVbG/
[code] => BdFjGTPFVbG
[date] => DateTime Object
(
[date] => 2017-12-24 14:29:34.000000
[timezone_type] => 3
[timezone] => Europe/Paris
)

[displaySrc] => https://scontent-cdg2-1.cdninstagram.com/vp/89ddb8f8c3466e7436c29d041ece4300/5B4AF306/t51.2885-15/e35/25024600_726096737595175_9198105573181095936_n.jpg
[caption] => 🎄🎅💸🙃 #casino #monaco
[comments] => 0
[likes] => 29
)
)
)
```

38 changes: 31 additions & 7 deletions src/Instagram/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ class Api
*/
private $maxId = false;

/**
* @var bool
*/
private $retrieveMediaData = false;

/**
* @var bool
*/
private $retrieveUserData = false;

/**
* Api constructor.
* @param Client|null $clientUser
Expand Down Expand Up @@ -68,38 +78,52 @@ public function setUserId($userId)
}

/**
* @param bool $fetchMedia
* @param bool $fetchUser
* @return Hydrator\Feed
* @throws InstagramException
*/
public function getFeed($fetchMedia = true, $fetchUser = false)
public function getFeed()
{
if (!$this->userName && !$this->userId) {
throw new InstagramException('Missing userName or userId');
}

if ($fetchUser && !$this->userName) {
if ($this->retrieveUserData && !$this->userName) {
throw new InstagramException('You must specify a userName to retrieve userData');
}

if (($fetchMedia || $this->maxId) && !$this->userId) {
if (($this->retrieveMediaData || $this->maxId) && !$this->userId) {
throw new InstagramException('You must specify a userId to retrieve mediaData');
}

$feed = new JsonFeed($this->clientUser, $this->clientMedia);
$hydrator = new Hydrator();

if ($fetchUser) {
if ($this->retrieveUserData) {
$userDataFetched = $feed->fetchUserData($this->userName);
$hydrator->setUserData($userDataFetched);
}

if ($fetchMedia) {
if ($this->retrieveMediaData) {
$mediaDataFetched = $feed->fetchMediaData($this->userId, $this->maxId);
$hydrator->setMediaData($mediaDataFetched);
}

return $hydrator->getHydratedData();
}

/**
* @param bool $retrieveMediaData
*/
public function retrieveMediaData($retrieveMediaData)
{
$this->retrieveMediaData = $retrieveMediaData;
}

/**
* @param bool $retrieveUserData
*/
public function retrieveUserData($retrieveUserData)
{
$this->retrieveUserData = $retrieveUserData;
}
}
Loading

0 comments on commit 3910319

Please sign in to comment.