当我尝试在Kohana进行Facebook身份验证时,我遇到了问题。
我的工作是:
在kohana中,我有一个名为loginview.php的视图文件,其中嵌入了此代码
href="https://www.facebook.com/dialog/oauth?client_id=341106515944015"&redirect_uri=http://verana.ge/fbauth/&scope=user_about_me&state=veranalast">
在控制器文件夹中我有一个名为fbauth.php的控制器,我有这个代码
public function action_index()
{
$app_id = "341106515944015";
$app_secret = "79f547b92f34f886cc8d51ca1a5d33e0";
$my_url = "http://verana.ge/";
// session_start(); <!-- commented because in Kohana the Session is already started -->
$code = $_REQUEST["code"];
if(empty($code)) {
$_SESSION['state'] = md5(uniqid(rand(), TRUE)); //CSRF protection
$dialog_url = "https://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url) . "&state="
. $_SESSION['state'];
echo("<script> top.location.href='" . $dialog_url . "'</script>");
}
if($_REQUEST["state"] = 'veranalast') {
$token_url = "https://graph.facebook.com/oauth/access_token?"
. "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret . "&code=" . $code;
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$graph_url = "https://graph.facebook.com/me?access_token="
. $params['access_token'];
$user = json_decode(file_get_contents($graph_url));
echo("Hello " . $user->name);
}
else {
echo("The state does not match. You may be a victim of CSRF.");
}
}
但是当我点击facebook链接并试图连接时我得到的错误说明如下
ErrorException [ Warning ]: file_get_contents(https://graph.facebook.com/oauth/access_token?client_id=341106515944015&redirect_uri=http%3A%2F%2Fverana.ge%2F&client_secret=79f547b92f34f886cc8d51ca1a5d33e0&code=AQB9jQDcWXNVhPoxhOH-GyJ_0P0UQD9y5wfFy8cfP48TxvlX0VnycEWSpTOC0NWXTyCfssTUHCwFjmZdySy74zor_AQGvtzE5YCkB3asMBhWiiAJhesbFa_GrQIzT7UWiNrbl73CmVz5hell-shwrnavUviuDvpMqg6jCbMBHa6nb39xvidf-P5KOe4wlyR9TG8) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad APPPATH/classes/controller/fbauth.php [ 32 ] 27 $token_url = "https://graph.facebook.com/oauth/access_token?" 28 . "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url) 29 . "&client_secret=" . $app_secret . "&code=" . $code; 30 31 32 $response = file_get_contents($token_url); 33 34 $params = null; 35 36 parse_str($response, $params); 37
也用于双重检查我在Kohana之外创建了这个功能,它没有问题。
我做的是外面Kohana我创建了由index.php命名的文件,其中我把html标记为 Facebook认证和下一个我创建的文件由testauth.php命名,其中我推特一样 代码,因为我把它放在fbauth.php中,正如我所说它没有问题。
可能是哪里有简单的方法来解决它,但我不知道它。请告诉我如何解决它。
任何Ides?
先谢谢你
答案 0 :(得分:0)
您是否尝试过https://graph.facebook.com/oauth/access_token?client_id=341106515944015&redirect_uri=http%3A%2F%2Fverana.ge%2F&client_secret=79f547b92f34f886cc8d51ca1a5d33e0&code=AQB9jQDcWXNVhPoxhOH-GyJ_0P0UQD9y5wfFy8cfP48TxvlX0VnycEWSpTOC0NWXTyCfssTUHCwFjmZdySy74zor_AQGvtzE5YCkB3asMBhWiiAJhesbFa_GrQIzT7UWiNrbl73CmVz5hell-shwrnavUviuDvpMqg6jCbMBHa6nb39xvidf-P5KOe4wlyR9TG8
?它产生400 HTTP错误。一切都很好。