doutao1939 2014-01-01 00:19
浏览 41
已采纳

使用php sdk的Facebook URL未加载

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

  • 写回答

1条回答 默认 最新

  • doulangbi6869 2014-01-01 00:28
    关注

    You're outputting logoutUrl rather than loginUrl

    Change:

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

    to use

    echo '<a href="'.$loginURL.'">Login</a>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?