Instagram with its unparalleled popularity has become an important member of social networks community and felt as indistinguishable entity to integrate into a website. Instagram can be easily integrated into a website using the Instagram API.
Let us go through the required steps for Instagram integration.
- Open https://www.instagram.com/ and login with your Instagram username and password.
- Scroll down to the bottom of the page and click API link in the footer. You will be directed to Instagram developer page.
- On the top menu bar, click the Manage Clients link.
- On redirected page, click on Register a New Client button to create your Instagram application and fill the required fields in the form
- Put a valid value like http://www.example.com/insta_api.php in redirect URL. This is the path to the file where the code for api integration is saved. ( Below you will find the insta_api.php )
- Finally click Register button to submit the form. On next page you will get Client ID and Client Secret to use the api.
Please note that every new app will be functioning in sand box mode first by default, so with limited Instagram features. To access all features of Instagram you need to switch your app into LIVE mode by following proper request procedure to get live. You will need to first get an access token to call the api methods.
Here is the full code to first get the access token and then to get user basic data as a test for Instagram integration.
$CLIENT_ID = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$CLIENT_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$REDIRECT_URI = 'http://www.example.com/insta_api.php';
$url = "https://api.instagram.com/oauth/authorize?client_id=$CLIENT_ID&redirect_uri=$REDIRECT_URI&response_type=code";
echo '<a href="'.$url.'">Login With Instagram</a>';
$authorize_code = $_GET['code'];
$insta_data = array(
'client_id' => $CLIENT_ID,
'client_secret' => $CLIENT_SECRET,
'grant_type' => 'authorization_code',
'redirect_uri' => $REDIRECT_URI,
'code' => $authorize_code
$url = 'https://api.instagram.com/oauth/access_token';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($insta_data));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
$json_result = json_decode($result);
Now run the redirect uri (given at the time of registering Instagram application). You will get a page with button Login With Instagram. Login with Instagram username and password and Authorize the application to get user data.