简体   繁体   中英

Facebook URL by using php sdk is not loading

I use the following code to connect to the facebook via my site, but the facebook page is not loading. The cook is like that

    <?php
require 'src/facebook.php';
$facebook = new Facebook(array(
  'appId'  => '198516340340394',
  'secret' => 'f11117b96e0996ecbf7d7f4919c0cf70',
  'cookie' => true
));
$user = $facebook->getUser();
$user_profile = null;
if ($user) {

try {
    $user_profile = $facebook->api('/me');
    $facebook->api('/me/feed/', 'post', array(
    'message' => 'I want to display this message on my wall'
));
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }

}

if ($user_profile) {
  $logoutUrl = $facebook->getLogoutUrl();
  echo '<a href="$logoutUrl">Logout</a>';
} else {
  $loginUrl = $facebook->getLoginUrl(array(
  'scope' => 'publish_stream, read_friendlists',
  ));
  echo '<a href="$logoutUrl">Login</a>';
}
?>

<html>
<head>
<title>PHP SDK</title>
</head>
<body>


</body>
</html>

and when I click on the login If you click on that login here it does not load the facebook

what should I do in this case

You're outputting logoutUrl rather than loginUrl

Change:

echo '<a href="$logoutUrl">Login</a>';

to use

echo '<a href="'.$loginURL.'">Login</a>';

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