$facebook->getSession() call breaks page below the call

别等时光非礼了梦想. 提交于 2020-01-17 01:49:04

问题


I have this code to log people in with Facebook:

<div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=my_app_id&amp;xfbml=1">
</script><fb:login-button show-faces="false" perms="user_hometown,user_about_me,email,user_address" autologoutlink="true" width="200" max-rows="1">
</fb:login-button>

<?php

if($facebook->getSession())
{
 // Nothing here yet
}

?>

But the call to $facebook->getSession() seems to break the page. Nothing below this call gets displayed. Any idea why? Or what I am doing wrong?

Here is the page where I am trying to test this: http://www.comehike.com/test_fb_connect.php


回答1:


If that's your entire PHP file then your referencing $facebook which hasn't been declared yet. You'll want to include the location of the PHP SDK then initialize $facebook with your appID and secret. This format has changed with v3.0.0 of the PHP SDK found here.

V 2.2.X

require '../src/facebook.php';

$facebook = new Facebook(array(
      'appId'  => '12345678910',
      'secret' => '*****************************',
    ));

$session = $facebook->getSession();
if ($session) {
  // proceed knowing you have a valid user session
} else {
  // proceed knowing you require user login and/or authentication
}

V 3.0.0

require '../src/facebook.php';

$facebook = new Facebook(array(
  'appId'  => '12345678910',
  'secret' => '*****************************',
));

$user = $facebook->getUser();
if ($user) {
  // proceed knowing you have a logged in user who's authenticated
} else {
  // proceed knowing you require user login and/or authentication
}


来源:https://stackoverflow.com/questions/6876629/facebook-getsession-call-breaks-page-below-the-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!