February 6, 2024 5:02 am

How to login with Instagram OAuth using PHP

We have created many open login systems like Facebook, Googletwitter, Microsoft and Linkedin etc and now we are going to give you an article on login with Instagram, Instagram is an online photo-sharing application which beautify your memories in pictures.

login-instagram-PHP

[wpdm_file id=47]DEMO

Here in this article we have used below files:

-config.php // Used for credentials

-index.php // Main file show login data

-instagram.class.php // Class file call data from instagram server

-instagram-login.png // Login button image

You have to register you app on Instagram

instagram-register-app

config.php

Contains key, secret and callback url

<?php
define('YOUR_APP_KEY', 'YOUR_APP_KEY'); 
define('YOUR_APP_SECRET', 'YOUR_APP_SECRET'); 
define('YOUR_APP_CALLBACK', 'YOUR_APP_CALLBACK'); 
?>

You can get your YOUR_APP_KEY and YOUR_APP_SECRET by Registering app on Instagram.

instagram-app-keys

Now come to the main file index.php

This file contains user information method and shows buttons.

require 'instagram.class.php';
require 'config.php';
    $instagram = new Instagram(array(
    'apiKey'      => YOUR_APP_KEY,
    'apiSecret'   => YOUR_APP_SECRET,
    'apiCallback' => YOUR_APP_CALLBACK
));

$code = $_GET['code'];
if (true === isset($code))
{
    $data = $instagram->getOAuthToken($code);
    print_r($data;)

}
else
{
    $loginUrl   = $instagram->getLoginUrl();
    echo "<a class=\"button\" href=\"$loginUrl\">Sign in with Instagram</a>";
}

In this code we used 2 extra files instagram.class.php and config.php

Created object $instagram and call login url with this method $instagram->getLoginUrl() once you approve access of your profile we use $data = $instagram->getOAuthToken($code) this method and pase $code to get user information.

So this is all you can download and test its demo also, comment your suggestions and problems which you faced in its implementation.

Author Huzoor Bux

I am Huzoor Bux from Karachi (Pakistan). I have been working as a PHP Developer from last 5+ years, and its my passion to learn new things and implement them as a practice. Basically I am a PHP developer but now days exploring more in HTML5, CSS and jQuery libraries.


Tutorial Categories:

6 responses to “How to login with Instagram OAuth using PHP”

  1. Soumya says:

    Can we get other information except basic information in instagram ?Please reply soon with procedure ?
    Advance Thanks.

  2. Mark Bagnall says:

    Can’t download the demo files

Leave a Reply

Your email address will not be published. Required fields are marked *