phphybridauthhybridauthprovider

How to add instagram oauth using Hybrid Auth?


When I am trying to add the Instagram OAuth With proper key credentials. It shows me a error like this. And yes I moved that instagram.php From third party provider to Providers

( ! ) Notice: Undefined index: id in C:\wamp\www\edit\hybridauth-2.6.0\hybridauth\Hybrid\Provider_Model_OAuth2.php on line 68
Call Stack
#   Time    Memory  Function    Location
1   0.0010  257688  {main}( )   ..\login-with.php:0
2   0.0090  748648  Hybrid_Auth::authenticate( )    ..\login-with.php:13
3   0.0090  748856  Hybrid_Auth::setup( )   ..\Auth.php:229
4   0.0090  750288  Hybrid_Provider_Adapter->factory( ) ..\Auth.php:277
5   0.0100  783760  Hybrid_Provider_Model->__construct( )   ..\Provider_Adapter.php:101
6   0.0100  785296  Hybrid_Providers_Instagram->initialize( )   ..\Provider_Model.php:96
7   0.0100  785832  Hybrid_Provider_Model_OAuth2->initialize( ) ..\Instagram.php:21
Missing provider application credentials.

Original error message: Your application id and secret are required in order to connect to Instagram
```

Login-with.php

<?php
        session_start();
        include('config.php');
        include('hybridauth-2.6.0/hybridauth/Hybrid/Auth.php');
        if(isset($_GET['provider']))
        {
            $provider = $_GET['provider'];

            try{

            $hybridauth = new Hybrid_Auth( $config );

            $authProvider = $hybridauth->authenticate($provider);

            $user_profile = $authProvider->getUserProfile();

            if($user_profile && isset($user_profile->identifier))
            {
                echo "<b>Name</b> :".$user_profile->displayName."<br>";
                echo "<b>Profile URL</b> :".$user_profile->profileURL."<br>";
                echo "<b>Image</b> :".$user_profile->photoURL."<br> ";
                echo "<img src='".$user_profile->photoURL."'/><br>";
                echo "<b>Email</b> :".$user_profile->email."<br>";
                        echo "<b>Email</b> :".$user_profile->identifier."<br>";                                             
                echo "<br> <a href='logout.php'>Logout</a>";
            }           

            }
            catch( Exception $e )
            { 

                 switch( $e->getCode() )
                 {
                        case 0 : echo "Unspecified error."; break;
                        case 1 : echo "Hybridauth configuration error."; break;
                        case 2 : echo "Provider not properly configured."; break;
                        case 3 : echo "Unknown or disabled provider."; break;
                        case 4 : echo "Missing provider application credentials."; break;
                        case 5 : echo "Authentication failed. "
                                         . "The user has canceled the authentication or the provider refused the connection.";
                                 break;
                        case 6 : echo "User profile request failed. Most likely the user is not connected "
                                         . "to the provider and he should to authenticate again.";
                                 $twitter->logout();
                                 break;
                        case 7 : echo "User not connected to the provider.";
                                 $twitter->logout();
                                 break;
                        case 8 : echo "Provider does not support this feature."; break;
                }

                // well, basically your should not display this to the end user, just give him a hint and move on..
                echo "<br /><br /><b>Original error message:</b> " . $e->getMessage();

                echo "<hr /><h3>Trace</h3> <pre>" . $e->getTraceAsString() . "</pre>";

            }

        }



?>

config.php

<?php

$config =array(
        "base_url" => "http://localhost/edit/hybridauth-2.6.0/hybridauth", 
        "providers" => array ( 

            "Google" => array ( 
                "enabled" => true,
                "keys"    => array ( "id" => "", "secret" => "" ), 
            ),

            "Facebook" => array ( 
                "enabled" => true,
                "keys"    => array ( "id" => "", "secret" => "" ), 
            ),

            "Twitter" => array ( 
                "enabled" => true,
                "keys"    => array ( "key" => "XXXXXXXX", "secret" => "XXXXXXXX" ),
            ),
            "Instagram" => array (
                "enabled" => true,
                "keys"    => array ( "key" => "my_instagram keys", "secret" => "my_instgram secret" ),

                ) 
        ),
        // if you want to enable logging, set 'debug_mode' to true  then provide a writable file by the web server on "debug_file"
        "debug_mode" => false,
        "debug_file" => "",
    );

Solution

  • Replace Key with id

       "keys" => array ( 
               "key" => "my_instagram keys", 
               "secret" => "my_instgram secret"
             )
    

    replace with

        "keys" =>array(
             "id" => "my_instagram keys",
             "secret" => "my_instgram secret" ) 
    

    it will work.