0

我正在使用下面的代码来检查用户是否登录到 Facebook。

<?php

// Awesome FB APP 
// Name: MyAPP 

require_once 'facebook.php';// this line calls our facebook.php file that is the 
//core of PHP facebook API
// Create our Application instance.

$facebook = new Facebook(array(

  'appId' => '250941738370233',

  'secret' => 'xxx',

  'cookie' => true,

)); // all we are doing is creating an array for facebook to use with our 

$user = $facebook->getUser();
echo $user;
//app id and app secret in and setting the cookie to true
if($user){
try {
  $user_profile = $facebook->api('/me');

} catch (FacebookApiException $e) {

  error_log($e);
  $user=null;

} // this code is saying if the session to the app is created use 
}
//the $me as a selector for the information or die

?>

但是 $user 每次都响应 0 。在这一点上我被严重卡住了。有人可以帮我吗?

4

2 回答 2

3

我正在使用下面的代码来检查用户是否登录到 Facebook。

我怀疑那是你的问题。

您无法检查访问您的应用程序的任何用户是否已登录 Facebook - 如果用户之前已连接到您的应用程序,您只会获得有关用户的信息。而且由于我在您的代码中没有看到类似的内容,因此我假设您之前没有以任何方式触发它。

所以请从这里开始阅读文档:https ://developers.facebook.com/docs/technical-guides/login/

于 2013-01-20T21:13:03.223 回答
0

得到一个 0 是意料之中的。您应该在获得该信息后将用户重定向到登录网址。如果您这样做,用户将获得您看到的那些应用程序授权屏幕之一,之后他们将被重定向到您指定的 whatevef url。

查看提供的链接,但也可以查看http://www.facebookanswers.co.uk/?p=229,因为我在那里提供了一些示例。

我的链接中的示例确实需要更新,但是如果您看一下,您会看到它会检查 getuser 是否返回 false,如果是则跳转到登录页面。

于 2013-01-21T07:12:22.417 回答