Package Data | |
---|---|
Maintainer Username: | sumardi |
Maintainer Contact: | me@sumardi.net (Sumardi Shukor) |
Package Create Date: | 2013-06-10 |
Package Last Update: | 2014-06-20 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-30 15:23:36 |
Package Statistics | |
---|---|
Total Downloads: | 8,069 |
Monthly Downloads: | 3 |
Daily Downloads: | 0 |
Total Stars: | 32 |
Total Watchers: | 3 |
Total Forks: | 4 |
Total Open Issues: | 1 |
A simple Laravel 4 service provider for including the PHP Instagram API.
The Instagram Service Provider can be installed via Composer by requiring the elevencodes/instagram-laravel
package.
{
"require": {
"laravel/framework": "4.1.*",
"php-instagram-api/php-instagram-api": "dev-master",
"elevencodes/instagram-laravel": "2.0.*@dev"
}
}
If you are using the Laravel 4.0, use
"elevencodes/instagram-laravel": "1.*"
instead.
To use the Instagram Service Provider, you must register the provider when bootstrapping your Laravel application.
Run config:publish
artisan command and update the package configuration file.
php artisan config:publish elevencodes/instagram-laravel
Find the providers
key in app/config/app.php
and register the Instagram Service Provider.
'providers' => array(
// ...
'Elevencodes\InstagramLaravel\InstagramLaravelServiceProvider',
)
Find the aliases
key in app/config/app.php
and add in our Instagram
alias.
'aliases' => array(
// ...
'Instagram' => 'Elevencodes\InstagramLaravel\Facades\InstagramLaravel',
)
The following example uses the Instagram Service Provider to authenticate user.
Add the following methods in your Users Controller.
public function getLogin()
{
if (Session::has(Config::get('instagram::session_name')))
Session::forget(Config::get('instagram::session_name'));
Instagram::authorize();
}
public function getAuthorize()
{
Session::put(Config::get('instagram::session_name'), Instagram::getAccessToken(Input::get('code')));
return Redirect::to('/');
}
public function getLogout()
{
Session::forget(Config::get('instagram::session_name'));
return Redirect::to('/');
}
Add the following routes in your routes.php
.
Route::get('/users/authorize', array('as' => 'authorize', 'uses' => 'UsersController@getAuthorize'));
Route::get('/login', array('as' => 'login', 'uses' => 'UsersController@getLogin'));
Route::get('/logout', array('as' => 'logout', 'uses' => 'UsersController@getLogout'));
You can use static call to get the current authenticated user.
$user = Instagram::getCurrentUser();