0

我的问题是:我从以下位置下载了 Facebook Php SDK:https ://github.com/facebook/facebook-php-sdk 我将所有内容放在一个文件夹中,并以这种方式创建了我的索引:

我的应用文件夹:

  • 源代码
  • 索引.php

在我的 index.php 中,我尝试了以下代码:

require_once("src/facebook.php");
$facebook = new Facebook(array('appId' => 666, 'secret' => 616));
die("why not zoidberg?");

但是我的应用程序不会死,也不会返回任何东西,一些想法?

接下来我尝试了这段代码,但只显示了第一个回显:

<?php     
echo "This is visible";
try{
require_once "src/facebook.php";
$facebook = new Facebook(array(
                                'appId' => '666',
                                'secret' => '616',
                                ));
}catch(ErrorException $e){
        echo error_reporting(E_ALL);
        die(var_dump($e));
}
die("This is not visible");

我的输出是:

This is visible
4

2 回答 2

0

这段代码非常适合我:

索引.php

<?

  require_once('src/facebook.php');

  $config = array(
    'appId' => 'myappId',
    'secret' => 'mysepratecode',
  );

  $facebook = new Facebook($config);
  $user_id = $facebook->getUser();
?>
<html>
  <head></head>
  <body>

  <?
    if($user_id) {

      // We have a user ID, so probably a logged in user.
      // If not, we'll get an exception, which we handle below.
      try {

        $user_profile = $facebook->api('/me','GET');
        echo "Name: " . $user_profile['name'];

      } catch(FacebookApiException $e) {
        // If the user is logged out, you can have a 
        // user ID even though the access token is invalid.
        // In this case, we'll get an exception, so we'll
        // just ask the user to login again here.
        $login_url = $facebook->getLoginUrl(); 
        echo 'Please <a href="' . $login_url . '">login.</a>';
        error_log($e->getType());
        error_log($e->getMessage());
      }   
    } else {

      // No user, print a link for the user to login
      $login_url = $facebook->getLoginUrl();
      echo 'Please <a href="' . $login_url . '">login.</a>';

    }

  ?>

  </body>
</html>
于 2012-07-30T11:09:47.600 回答
0

解决了,我没有安装 Json 和 Curl ;)

于 2012-07-30T14:34:37.897 回答