Php Hybridauth(重定向到网站,无需登录fb)
我仍然在学习这个杂交人,我遵循这个指示 当我尝试登录facebook时,它会重定向到我的网站(尚未登录fb),在显示配置文件后,它应该重定向到登录facebook(使用.php登录) 我的朋友喜欢这样 login.html:Php Hybridauth(重定向到网站,无需登录fb),php,facebook,facebook-graph-api,hybridauth,Php,Facebook,Facebook Graph Api,Hybridauth,我仍然在学习这个杂交人,我遵循这个指示 当我尝试登录facebook时,它会重定向到我的网站(尚未登录fb),在显示配置文件后,它应该重定向到登录facebook(使用.php登录) 我的朋友喜欢这样 login.html: <html> <head></head> <body align="center"> <div align="center"> <h1>Login with Facebook,Twit
<html>
<head></head>
<body align="center">
<div align="center">
<h1>Login with Facebook,Twitter & Google</h1>
<a href="login-with.php?provider=Facebook"><img src='facebook.png'></img></a> <br><br>
<a href="login-with.php?provider=Twitter"><img src='twitter.png'></img></a> <br><br>
<a href="login-with.php?provider=Google"><img src='google.png'></img></a><br><br>
</div>
</body>
</html>
使用Facebook、Twitter和Google登录
login-with.php:
<?php
session_start();
include('config.php');
include('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 "<br> <a href='logout.php'>Logout</a><br/>";
echo "<b>Hello Dear</b> :".$user_profile->displayName."<br>";
echo "<b>Profile URL</b> :".$user_profile->profileURL."<br>";
echo "<img src='".$user_profile->photoURL."'/><br>";
echo "<b>Email</b> :".$user_profile->email."<br>";
echo "<b>Image</b> :".$user_profile->photoURL."<br> ";
}
}
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>";
}
}
?>
<?php
$config =array(
"base_url" => "http://website.com/",
"providers" => array(
// openid providers
"OpenID" => array(
"enabled" => true
),
"Yahoo" => array(
"enabled" => true,
"keys" => array("key" => "", "secret" => ""),
),
"AOL" => array(
"enabled" => true
),
"Google" => array(
"enabled" => true,
"keys" => array("id" => "", "secret" => ""),
),
"Facebook" => array(
"enabled" => true,
"keys" => array("id" => "xxxxxxxxxxxxxxx", "secret" => "xxxxxxxxxxxxxxxxxxx"),
"scope" => "email, user_about_me, user_birthday, user_hometown",
),
"Twitter" => array(
"enabled" => true,
"keys" => array("key" => "", "secret" => ""),
"includeEmail" => false
),
// windows live
"Live" => array(
"enabled" => true,
"keys" => array("id" => "", "secret" => "")
),
"LinkedIn" => array(
"enabled" => true,
"keys" => array("key" => "", "secret" => "")
),
"Foursquare" => array(
"enabled" => true,
"keys" => array("id" => "", "secret" => "")
),
),
"debug_mode" => false,
"debug_file" => "",
);