Facebook PHP Sdk返回重定向uri是必需的

时间:2016-01-15 20:11:42

标签: php facebook

我正在尝试使用facebook php sdk进行身份验证,但返回错误

  

参数redirect_uri是必需的

enter image description here

你可以在redirect_uri上面的url中看到它的值。

这是我正在使用的代码

  

的config.php

<?php
//CONFIGURE YOU APP HERE
define("APP_ID","abcd");//REPLACE THIS WITH YOUR FACEBOOK APP ID
define("APP_SECRET","abcd");//REPLACE THIS WITH YOUR FACEBOOK APP SECRET
define("CALLBACK_URI","https://example.com/callback.php");//REPLACE THIS WITH YOU CALLBACK URL [This is where facebook will redirect user after login]
define("LOGOUT_REDIRECT_URL","https://example.com/close.php");//REPLACE THIS WITH URL OF YOU LOGIN PAGE    

/** APP CONFIGURATION END HERE **/


//NO NEED TO CHANGE BELOW ANYTHING 
require_once('facebook-php-sdk-v4-5.0.0/src/Facebook/autoload.php');//LOADS FACEBOOK SDK
session_start();
$fb = new Facebook\Facebook([
  'app_id' => APP_ID,
  'app_secret' => APP_SECRET,
  'default_graph_version' => 'v2.5',
  ]);
?>
  

的login.php

<?php
require_once('config.php');//Loads configration

$helper = $fb->getRedirectLoginHelper();

$permissions = ['email']; // PERMISSIONS YOU WOULD LIKE TO ACCESS
$loginUrl = $helper->getLoginUrl(CALLBACK_URI, $permissions);

//$loginUrl =  '<a href="' . htmlspecialchars($loginUrl) . '">Log in with Facebook!</a>';
$loginUrl = htmlspecialchars($loginUrl);
header("location: $loginUrl");
exit();
?>

2 个答案:

答案 0 :(得分:3)

不接受网址中的'&amp;'。必须是&amp;代替。

答案 1 :(得分:0)

我有同样的问题,但我想出了我的: $ facebook = new Facebook \ FacebookRedirectLoginHelper(URL)与我在developers.facebook网站上的不同。