简体   繁体   中英

Facebook PHP sdk error. Cannot get public profile

I downloaded the facebook php-sdk and I updated it with my app id and app secret. Then I used ftp to upload it to my server. It is a windows server.

But when I run the example.php file, in the example folder, it always shows not connected. Even when I clicked on "Login with Facebook" button. But it returned a url like this:

http://freelankan.cu.cc/examples/example.php?code=AQATeuQKc2tmSHuy6SHyej......

I want to integrate my native login system with facebook's login. Is this happening because of a problem with my server or a problem in code?

Code:

<?php

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


$facebook = new Facebook(array(
  'appId'  => '8530403454382687',
  'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
));


$user = $facebook->getUser();


if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}

// Login or logout url will be needed depending on current user state.
if ($user) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {
  $statusUrl = $facebook->getLoginStatusUrl();
  $loginUrl = $facebook->getLoginUrl();
}



if($user) {
    echo '<a href="'.$logoutUrl.'Logout</a>';
} else {
    echo '<a href="'.$loginUrl.'">Login</a>';
}
?>

This was happend because web hosting provider did not allow to communicate with facebook.
i think some provider does this. (most of free web hosting providers)
when i got a paid hosting. this error did not happend again.
hope this will help full.

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