Today, We want to share with you OAuth Login with Facebook and Twitter using PHP.
In this post we will show you Login with Facebook using PHP, hear for we will give you demo and example for implement.In this post, we will learn about OAuth Login for Facebook Twitter and Google Plus Using PHP with an example.
Login with Facebook and Twitter using PHP
There are the Following The simple About OAuth Login with Facebook and Twitter using PHP Full Information With Example and source code.
Steps 1 : Download HybridAuth PHP library
Steps 1: first of all We have simple used redymate library such as a HybridAuth Library with this step by step fully working example, Therefor you simple here need all the source code download HybridAuth PHP library from here all source code on Github.
Steps 2 : Create Facebook and Twitter developer Account
Now, Steps 2: You some legaly should to retrive main social Developer main API(OAuth – authentication) Key as well as get Secret from your Developer accounts created and get all config data in Facebook and Twitter for Login with Facebook and Twitter using PHP.
Steps 3 :config for Twitter with Facebook
Steps3: And then you should to make simple changes config.php as well as put here below source code to this file.
[php]
$config =array(
“base_url” => “https://infinityknow.com/demo/login-with-facebook-twitter-php/hybridauth/index.php”,
“sources” => array (
“Facebook” => array (
“enabled” => true,
“keys” => array ( “id” => “Inf454nityPak574infops5SSkd”, “secret” => “Inf454nityPak574infops5SSkd” ),
),
“Twitter” => array (
“enabled” => true,
“keys” => array ( “key” => “Inf454nityPak574infops5SSkd”, “secret” => “Inf454nityPak574infops5SSkd” )
),
),
“debug_mode” => false,
“debug_file” => “”,
);
[/php]
Auto Post Tweets on Twitter via API Using PHP
Steps 4 : Facebook and Twitter Login(index.php)
Steps 4: and then make a simple main root file name index.php as well as put the below source code.
[php]
[/php]
Steps 5 : Login with Facebook and Twitter
Steps 5: Now, You will should to make new login.php as well put The below source code.
[php]
authenticate($source);
$scoial_profile = $authProvider->getUserProfile();
if($scoial_profile && isset($scoial_profile->identifier)) {
echo “Your Name :”.$scoial_profile->displayName.”
“;
echo “Img URL :”.$scoial_profile->profileURL.”
“;
echo “Your Image :”.$scoial_profile->photoURL.”
“;
echo “Logout“;
}
}
catch( Exception $e ) {
switch( $e->getCode() ) {
case 0 : echo “Unspecified some stuck error.”; break;
case 1 : echo “Hybridauth libs configuration error.”; break;
case 2 : echo “Provider not good configured.”; break;
case 3 : echo “Unknown or disabled source.”; break;
case 4 : echo “Missing source any devloper application credentials.”; break;
case 5 : echo “Authentication failed. ”
. “The clients has canceled the web authentication or the source refused the main connection.”;
break;
case 6 : echo “clients your request failed. Most likely the clients is not connected ”
. “to the source and he should to authenticate again.”;
$twitter->logout();
break;
case 7 : echo “clients not connected to the source.”;
$twitter->logout();
break;
case 8 : echo “Provider does not proviedes this feature.”; break;
}
echo “
Original error message: ” . $e->getMessage();
echo “
Trace
" . $e->getTraceAsString() . "
“;
}
}
?>
[/php]
Step 6 : Logout with Facebook and Twitter
Steps 6:Last step to make file name logout.php with the below some source code to handle your all the pages not access with logout functionality.
[php]
[/php]
Read :
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about Login with Facebook and Twitter.
I would like to have feedback on my Infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.