2011-08-05 16 views
1

这里是我的代码:的Facebook-PHP-SDK:API( '/我')没有工作,很奇怪

$session = $facebook->getSession(); 
var_dump($session);/*it says session is perfectly established*/ 
try { 
    $uid = $facebook->getUser(); 
    echo '<br>'; 
    var_dump($uid);/*User id is found*/ 
    $fb_user = $me = $facebook->api('/me');/*PHP execution doesn't go forward, here it breaks*/ 
    echo '<br>'; 
    var_dump($fb_user);/*PHP execution doesn't come up to here*/ 

编辑: 我已经print_r的在闭锁段的$异常,并得到了下面的长消息:

FacebookApiException Object 
(
    [result:protected] => Array 
     (
      [error_code] => 6 
      [error] => Array 
       (
        [message] => name lookup timed out 
        [type] => CurlException 
       ) 

     ) 

    [message:protected] => name lookup timed out 
    [string:private] => 
    [code:protected] => 6 
    [file:protected] => /home/abusadat/public_html/.../facebook.php 
    [line:protected] => 614 
    [trace:private] => Array 
     (
      [0] => Array 
       (
        [file] => /home/abusadat/public_html/.../facebook.php 
        [line] => 575 
        [function] => makeRequest 
        [class] => Facebook 
        [type] => -> 
        [args] => Array 
         (
          [0] => https://graph.facebook.com/me 
          [1] => Array 
           (
            [method] => GET 
            [access_token] => ******...****** 
           ) 

         ) 

       ) 

      [1] => Array 
       (
        [file] => /home/abusadat/public_html/.../facebook.php 
        [line] => 539 
        [function] => _oauthRequest 
        [class] => Facebook 
        [type] => -> 
        [args] => Array 
         (
          [0] => https://graph.facebook.com/me 
          [1] => Array 
           (
            [method] => GET 
           ) 

         ) 

       ) 

      [2] => Array 
       (
        [file] => /home/abusadat/public_html/.../facebook.php 
        [line] => 492 
        [function] => _graph 
        [class] => Facebook 
        [type] => -> 
        [args] => Array 
         (
          [0] => /me 
         ) 

       ) 

      [3] => Array 
       (
        [file] => /home/abusadat/public_html/.../fb-connect.php 
        [line] => 31 
        [function] => api 
        [class] => Facebook 
        [type] => -> 
        [args] => Array 
         (
          [0] => Array 
           (
            [0] => Facebook Object 
             (
              [appId:protected] => ******...****** 
              [session:protected] => Array 
               (
                [access_token] => ******...****** 
                [base_domain] => abusadat.com 
                [expires] => 1312567200 
                [secret] => ******...****** 
                [session_key] => ******...****** 
                [sig] => ******...****** 
                [uid] => ******...****** 
               ) 

              [signedRequest:protected] => 
              [sessionLoaded:protected] => 1 
              [cookieSupport:protected] => 1 
              [baseDomain:protected] => 
              [fileUploadSupport:protected] => 
             ) 

            [1] => _graph 
           ) 

          [1] => Array 
           (
            [0] => /me 
           ) 

         ) 

       ) 

      [4] => Array 
       (
        [file] => /home/abusadat/public_html/.../index.php 
        [line] => 29 
        [args] => Array 
         (
          [0] => /home/abusadat/public_html/.../fb-connect.php 
         ) 

        [function] => include_once 
       ) 

     ) 

) 

我使用SDK 2.1.2版。我有一些使用SDK 3或更高版本的限制。

回答

1

我的猜测是抛出了一个异常,并且你没有看到它,因为你的PHP错误报告设置没有正确调整。

添加到您的PHP文件的顶部:

ini_set('display_errors', 1); 
error_reporting(E_ALL); 

之后,应看到一个PHP错误访问该页面时。

+0

我已经试过你说过的方式。但没有任何区别。 – Sadat

+0

你能告诉我们完整的代码吗?你有一个尝试claue,但你不显示catch子句。如果抛出异常,你在做什么? – sagi

+0

你是对的。我有print_r $异常,并收到错误消息。请查看该错误消息的编辑部分 – Sadat