Skip to content

Commit

Permalink
Update lib + add access token
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrimaud committed Apr 16, 2018
1 parent 2859e08 commit 9e84e68
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 547 deletions.
243 changes: 32 additions & 211 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,175 +11,37 @@
```
composer require pgrimaud/instagram-user-feed
```

1. Visit [http://instagram.pixelunion.net/](http://instagram.pixelunion.net/) and create an access token

2. The first part of the access token is your User Id

```
$api = new Api();
$api->setAccessToken('1234578.abcabc.abcabcabcabcabcabcabcabcabcabc');
$api->setUserId(1234578);
```



Seems like you can only access your own media until 2020 other user's media December 11, 2018. Hope to find a solution for long term.

## Warning

**2018-04-08 : Due to changes of the Instagram API (again...), you must upgrade to version ^3.0**
**2018-04-16 : Now fetching data with access token, only for your account (thanks @jannejava), please upgrade to version ^4.0**

~~2018-04-08 : Due to changes of the Instagram API (again...), you must upgrade to version ^3.0~~

~~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');

$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] => 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
(
[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
)
...
)
)
```

### Retrieve all data
### Retrieve 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);
$api->setAccessToken('1234578.abcabc.abcabcabcabcabcabcabcabcabcabc');

$feed = $api->getFeed();

Expand All @@ -193,80 +55,39 @@ 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
[biography] => Gladiator retired - ESGI 14'
[followers] => 342
[following] => 114
[profilePicture] => https://scontent.cdninstagram.com/vp/f49bc1ac9af43314d3354b4c4a987c6d/5B5BB12E/t51.2885-19/10483606_1498368640396196_604136733_a.jpg
[externalUrl] => https://p.ier.re/
[mediaCount] => 30
[mediaCount] => 33
[hasNextPage] => 1
[maxId] => 1230468487398454311_184263228
[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
[id] => 1758133053345287778_184263228
[typeName] => image
[height] => 640
[width] => 640
[thumbnailSrc] => https://scontent.cdninstagram.com/vp/e64c51de7f5401651670fd0bbdfd9837/5B69AF2B/t51.2885-15/s150x150/e35/30604700_183885172242354_7971196573931536384_n.jpg
[link] => https://www.instagram.com/p/BhmJLJwhM5i/
[date] => DateTime Object
(
[date] => 2017-12-24 14:29:34.000000
[date] => 2018-04-15 17:23:33.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
[displaySrc] => https://scontent.cdninstagram.com/vp/dd39e08d3c740e764c61bc694d36f5a7/5B643B2F/t51.2885-15/s640x640/sh0.08/e35/30604700_183885172242354_7971196573931536384_n.jpg
[caption] =>
[comments] => 2
[likes] => 14
)
...
...
)
)
)
```

### Paginate
Expand All @@ -277,18 +98,18 @@ If you want to use paginate for user media data, retrieve `endCursor` from previ

$api = new Api();
$api->setUserId(184263228);
$api->retrieveMediaData(true);
$api->setAccessToken('1234578.abcabc.abcabcabcabcabcabcabcabcabcabc');

$feed = $api->getFeed();

$endCursor = $feed->getEndCursor();
$endCursor = $feed->getMaxId();

// Second call :

$api = new Api();
$api->setUserId(184263228);
$api->retrieveMediaData(true);
$api->setEndCursor($endCursor);
$api->setAccessToken('1234578.abcabc.abcabcabcabcabcabcabcabcabcabc');
$api->setMaxId('1230468487398454311_184263228');

$feed = $api->getFeed();

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"require-dev": {
"phpunit/phpunit": "5.4.*",
"codeclimate/php-test-reporter": "dev-master",
"friendsofphp/php-cs-fixer": "^2.4"
"friendsofphp/php-cs-fixer": "^2.4",
"codeclimate/php-test-reporter": "^0.4.4"
}
}
22 changes: 10 additions & 12 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9e84e68

Please sign in to comment.