dongqin8652 2014-07-30 00:48
浏览 74
已采纳

新的Facebook PHP SDK生成空白页面

Well I've tried to find something on the new Facebook PHP SDK V4 to see if anyone else is having issues and according to some tutorial comments there have been many complaints to Facebook Developers site about the new SDK but will see if anyone here has found a way around it.

So I've set up my new Facebook App the same way I set up any other app in the past. I have my App ID and Secret and have set up my index.php page as follows:-

<?php

session_start();
require_once('Facebook/FacebookSession.php');
require_once('Facebook/FacebookCanvasLoginHelper.php');
require_once('Facebook/FacebookRedirectLoginHelper.php');
require_once('Facebook/FacebookRequest.php');
require_once('Facebook/FacebookResponse.php');
require_once('Facebook/FacebookSDKException.php');
require_once('Facebook/FacebookRequestException.php');
require_once('Facebook/FacebookAuthorizationException.php');
require_once('Facebook/GraphObject.php');
require_once('Facebook/GraphUser.php');
require_once('Facebook/GraphSessionInfo.php');

use Facebook\FacebookSession;
use Facebook\FacebookCanvasLoginHelper;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\GraphUser;
use Facebook\GraphSessionInfo;

$app_id = '..........';
$app_secret = '...........';

FacebookSession::setDefaultApplication($app_id, $app_secret);

$helper = new FacebookCanvasLoginHelper();

try {
$session = $helper->getSession();
} catch (Exception $e) {
echo 'Error: '.$e->getMessage();
}

if ($session) {
//$_SESSION['token'] = $session->getToken();
echo 'Logged In!';
try {
    $request = new FacebookRequest($session, 'GET', '/me');
    $response = $request->execute();
    $graph = $response->getGraphObject();
    echo 'Hi '.$graph->getProperty('name');
} catch (FacebookRequestException $e) {
    echo $e->getMessage();
} 
}
else {
//echo '<a href="'.$helper->getLoginUrl().'">Login</a>';
$helper = new FacebookRedirectLoginHelper('https://apps.facebook.com/event-lister');
$auth_url = $helper->getLoginUrl(array('email', 'user_friends'));
echo '<script>window.top.location.href="'.$auth_url.'"></script>';
}
?>

Apologies for pasting everything in but had to make sure I was thorough in there being everything that was needed in the index.php file.

This produces a blank page and doesn't even offer the opportunity to log in. I've followed two tutorials with no success and the Facebook App has been configured correctly with the correct canvas URL etc... in place

Please can someone let me know if they have had the same issues and if so how did you overcome them or is it an on going thing that Facebook know about and are busy trying to fix? Or have I gone wrong somewhere?

  • 写回答

1条回答 默认 最新

  • dpfz27768 2014-07-30 04:34
    关注

    I have had issues like this with the API. If it is a blank page most likely it is an error in your PHP. Enable error reporting by putting this at the top of the page on any page that is being loaded.

    <?php
         error_reporting(E_ALL);
         ini_set('display_errors', 1);
    ?>
    

    Also since a lot of people were having problems with the FB api login script. I made one detailing a few lines of code to change to get it up and running. I also included a copy of the V4 FBapi. Just get it off the github page and follow the readme instructions and you will be up and running in 5 minutes.

    Click Here

    You will also find an example of making api calls to gain information about the user and returning to an array. You can easily build on to this array with any data you may need.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 CSS实现渐隐虚线框
  • ¥15 有没有帮写代码做实验仿真的
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真