Instagram API PHP Class
2 minutes read
I've been building a lot of Facebook applications lately. They range from simple data capture forms behind fan gates to long surveys, and I try to keep the UI simple and engaging in all of them.
Along the way I've used a few RESTful APIs, including Facebook Open Graph, Twitter, Instagram, Spotify and Beatport. Instagram is the one I ended up using most, so that's what this post is about.
There were no libraries built on its SDKs, and working with the API without one is a story for another day. After a lot of trouble I wrote my own PHP class to make the API's methods easier to call. This is a very early version. A few important methods are missing and I'll add them over the next few days, but what's there is enough to authorise a user and fetch their basic information.
The package has two files:
instagram.class.phpig-config.php, which holds the configurationinstagram.class.phpneeds
Usage
- Include or require
instagram.class.php. - Create an instance:
$ig = new JRIG( parameters );
Parameters:
$client_id
$client_secret
$redirect_uri
$scope
All parameters are optional. By default the instance reads them from ig-config.php. Pass them in when you want an instance for a different registered Instagram client.
These methods are available on an instance:
// returns an Instagram OAuth URI
$ig->get_oauth_uri();
// returns client id
$ig->get_client_id();
// returns client secret
$ig->get_client_secret();
// returns scopes/permissions
$ig->get_scope();
// returns user basic information including access_token as an associative Array()
$ig->get_access_token();
The release has a few other methods too. It's on GitHub under the MIT License if you want to use it or contribute.
Example: http://jabran.me/sandbox/igapi/