我仍在学习这个hybridauth,我遵循这个website的指示。
当我尝试在Facebook登录时,它会重定向到我的网站(尚未登录fb),应该在该显示配置文件(login-with.php)之后重定向到登录facebook。
和我的href一样http://website.com/?hauth.start=Facebook&hauth.time=1467301785
login.html:
<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>
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>";
}
}
?>
Config.php:
<?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" => "",
);
我错在哪里?谢谢你的进步。