Package Data | |
---|---|
Maintainer Username: | emmanueln_nike |
Maintainer Contact: | free2liveb4u@gmail.com (Emmanuel Ikechukwu N) |
Package Create Date: | 2016-09-03 |
Package Last Update: | 2016-09-09 |
Language: | PHP |
License: | GNU |
Last Refreshed: | 2024-12-15 15:10:49 |
Package Statistics | |
---|---|
Total Downloads: | 85 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 0 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Updated Instagram API for Laravel
A PHP wrapper for the Instagram API. Feedback or bug reports are appreciated.
Composer package available.
Supports Instagram Video and Signed Header.
To use the Instagram API you have to register yourself as a developer at the Instagram Developer Platform and create an application. Take a look at the uri guidelines before registering a redirect URI. You will receive your client_id
and client_secret
.
Please note that Instagram mainly refers to »Clients« instead of »Apps«. So »Client ID« and »Client Secret« are the same as »App Key« and »App Secret«.
A good place to get started is the example project.
I strongly advice using Composer to keep updates as smooth as possible.
$ composer require "emmanueln-nike/instagram:dev-master"
Add the service provider to config/app.php in the providers array
$ Emmanueln\Instagram\InstagramServiceProvider::class
Publish the configuration file by running the command
$ php artisan vendor:publish --provider="Emmanueln\Instagram\InstagramServiceProvider"
This will create a instagram.php file in your config directory. Here you must enter your Instagram Api Key, Api Secret, and Callback URL.
use Emmanueln\Instagram\Instagram;
$instagram = new Instagram(array(
'apiKey' => 'YOUR_APP_KEY',
'apiSecret' => 'YOUR_APP_SECRET',
'apiCallback' => 'YOUR_APP_CALLBACK'
));
echo "<a href='{$instagram->getLoginUrl()}'>Login with Instagram</a>";
// grab OAuth callback code
$code = $_GET['code'];
$data = $instagram->getOAuthToken($code);
echo 'Your username is: ' . $data->user->username;
// set user access token
$instagram->setAccessToken($data);
// get all user likes
$likes = $instagram->getUserLikes();
// take a look at the API response
echo '<pre>';
print_r($likes);
echo '<pre>';
All methods return the API data json_decode()
- so you can directly access the data.
new Instagram(<array>/<string>/<null>);
array
if you want to authenticate a user and access its data without using the config/instagram.php:
new Instagram(array(
'apiKey' => 'YOUR_APP_KEY',
'apiSecret' => 'YOUR_APP_SECRET',
'apiCallback' => 'YOUR_APP_CALLBACK'
));
string
if you only want to access public data:
new Instagram('YOUR_APP_KEY');
null
if you want to authenticate a user and access its data the config/instagram.php:
new Instagram();
Note that using the null
, you must have your configurations setup in the config/instagram.php file
getLoginUrl(<array>)
getLoginUrl(array(
'basic',
'likes'
));
Optional scope parameters:
getOAuthToken($code, <true>/<false>)
true
: Returns only the OAuth token
false
[default] : Returns OAuth token and profile data of the authenticated user
setAccessToken($token)
getAccessToken()
Public methods
getUser($id)
searchUser($name, <$limit>)
getUserMedia($id, <$limit>)
Authenticated methods
getUser()
getUserLikes(<$limit>)
getUserFeed(<$limit>)
getUserMedia(<$id>, <$limit>)
$id
isn't defined or equals 'self'
, it returns the media of the logged in userAuthenticated methods
getUserFollows()
getUserFollower()
getUserRelationship($id)
modifyRelationship($action, $user)
$action
: Action command (follow / unfollow / block / unblock / approve / deny)$user
: Target user id// Follow the user with the ID 1574083
$instagram->modifyRelationship('follow', 1574083);
Please note that the modifyRelationship()
method requires the relationships
scope.
Public methods
getMedia($id)
getPopularMedia()
searchMedia($lat, $lng, <$distance>, <$minTimestamp>, <$maxTimestamp>)
$lat
and $lng
are coordinates and have to be floats like: 48.145441892290336
,11.568603515625
$distance
: Radial distance in meter (default is 1km = 1000, max. is 5km = 5000)$minTimestamp
: All media returned will be taken later than this timestamp (default: 5 days ago)$maxTimestamp
: All media returned will be taken earlier than this timestamp (default: now)Public methods
getMediaComments($id)
Authenticated methods
addMediaComment($id, $text)
apidevelopers[at]instagram.com
for accessdeleteMediaComment($id, $commentID)
Please note that the authenticated methods require the comments
scope.
Public methods
getTag($name)
getTagMedia($name)
searchTags($name)
Authenticated methods
getMediaLikes($id)
likeMedia($id)
deleteLikedMedia($id)
How to like a Media: Example usage Sample responses of the Likes Endpoints.
All <...>
parameters are optional. If the limit is undefined, all available results will be returned.
Instagram entries are marked with a type
attribute (image
or video
), that allows you to identify videos.
An example of how to embed Instagram videos by using Video.js, can be found in the /example
folder.
Please note: Instagram currently doesn't allow to filter videos.
In order to prevent that your access tokens gets stolen, Instagram recommends to sign your requests with a hash of your API secret, the called endpoint and parameters.
$instagram->setSignedHeader(true);
Go into more detail about how it works in the Instagram API Docs.
Each endpoint has a maximum range of results, so increasing the limit
parameter above the limit won't help (e.g. getUserMedia()
has a limit of 90).
That's the point where the "pagination" feature comes into play.
Simply pass an object into the pagination()
method and receive your next dataset:
$photos = $instagram->getTagMedia('kitten');
$result = $instagram->pagination($photos);
Iteration with do-while
loop.
Check the instagram docs for samples of redirect uri Instagram API docs.
This example project, located in the tests/example/
folder, helps you to get started.
The code is well documented and takes you through all required steps of the OAuth2 process.
Credit for the awesome Instagram icons goes to Ricardo de Zoete Pro.
Let me know if you have to share a code example, too.
Copyright (c) 2016 - Emmanuel Ikechukwu N.
Credits to Christian Metz (Initial author) - http://cosenary.github.com/Instagram-PHP-API
Released under the GNU License.