简体   繁体   中英

$me = $facebook->api('/me') does not return any value

I am developing a facebook iframe application with the New Graph API php sdk. I am using the basic code to just display my name. But it does not return any value. Some one please help me with this.

<?php  

  include_once 'facebook.php';  
  include_once 'config.php';  

  $facebook = new Facebook(array('appId'  => FACEBOOK_APP_ID,  
                                 'secret' => FACEBOOK_SECRET_KEY,  
                                 'cookie' => true,));  

  $session = $facebook->getSession();
  $me = null;

  if ($session) {
    try {  
        $uid = $facebook->getUser();
        echo "Hello " . $uid . "<br />";   // This is displayed with my User Id

        $me = $facebook->api('/me');
       echo "Hello " . $me['name'] . "<br />";  // This is not displayed.

    } catch (FacebookApiException $e) {
        error_log($e);
    }
  }

if ($me) {
    $logoutUrl = $facebook->getLogoutUrl();
} else {
    $loginUrl = $facebook->getLoginUrl();
}

Why is my name not displayed?

Edit 1

If I use the example code that comes with the New Graph API facebook sdk zip folder, I get the following error:

 Fatal error: Uncaught CurlException: 6: 
 Could not resolve host: graph.facebook.com; 
 No data record of requested type thrown in
 C:\xampplite\htdocs\newtest\facebook.php on line 513

where line no 513 is:

 $e = new FacebookApiException(array(
    'error_code' => curl_errno($ch),
    'error'      => array(
      'message' => curl_error($ch),
      'type'    => 'CurlException',
    ),
  ));

Please explain me what is wrong. I searched for the error explanation in google,but i couldn't get much information. What is the error I have made?

try writing the following code in the try block where you have called the this($me = $facebook->api('/me');) api.

Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYPEER] = false; Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYHOST] = 2;

let us tack a look at the error by the following script:

try {
    $uid = $facebook->getUser();
    $fbme = $facebook->api('/me');
} catch (FacebookApiException $e) { 
    print_r($e);
}

Error:

[error] => Array
(
    [message] => Failed to connect to 66.220.147.27: Permission denied
    [type] => CurlException
)

outgoing connections are filtered by the server firewall. Refer to your hosting support for additional information how to allow the connection to external host.

Note that you can also disable the firewall, and everything will work well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM