Yii and instagram API

Yii and instagram API PHP

Instagram is a free photo-sharing program and social network that was launched in October 2010. The service enables users to take a photo, apply a digital filter to it, and then share it with other Instagram users they are connected to on the social network as well as on a variety of social networking services.

Too many developed great apps for this platform such as statigr.am which is a great implementation of the public API.

instagram gives developers a great API, however there’s a php API of course based on the original instagram API but much more simpler to use in your PHP project.

This API called PHP-Instagram-API .

To use this API in your Yii project please download it from here.

extract to downloaded ZIP file. You will see three folders “Examples”, “Instagram”, “Tests”.
Just take “Instagram” folder and place it under “protected/components/”.

I created a nice class and called it InstaConnect, which you can place all your functions inside it (in components folder).

So to implement this class please see the “Example” folder and add the functions you need.
As you can see before you can use the API you should obtain the ClientID and AccessToken.

ClientID
Go to instagram website and register your website and your app.

Authentication (AccessToken)
Set up a client for use with Instagram’s API

Create an Auth Object and pass in the information from the API

Then you have to get the user to authorize your app

This will redirect the user to the Instagram authorization page. After authorization Instagram will redirect the user to the url in $auth_config[‘redirect_uri’] with a code that you will need to obtain an access token

Then use the access token in your code.

Limits:
Be nice. If you’re sending too many requests too quickly, you will have a 503 error code (server unavailable).

You are limited to 5000 requests per hour per access_token or client_id overall. Practically, this means you should (when possible) authenticate users so that limits are well outside the reach of a given user.

Note:

  • There’s a Yii extension, but I prefer to use a simple API instead.
  • PHP instagram API works only with PHP 5.3+ since it’s using namespacing.

if you have any questions please feel free to comment.
Thanks for reading.

If you think something is wrong please feel free to comment :)