繁体   English   中英

facebook用户身份验证并在用户墙上发布

[英]facebook user authentication and post on user wall

我遵循了这个视频教程,但是我陷入了困境。当我单击登录链接时,浏览器继续加载,然后什么也没有发生,仍然登录页面在我面前。它总是在$ user_id中返回0.它向我显示了Facebook身份验证第1至2页,之前我单击了“允许”,但现在什么也没有发生。另一件事,当我单击登录链接时,浏览器的网址从

“ http://localhost/php/fbdata.php”

的“http://localhost/php/fbdata.php状态= e1d5ccf919c6a9d3325200596c12b447&代码= AQDg8hE1GuKQ6eq9nGeLV8BIK8EjeIuY8Drf6g0FwAWAjGkvFi70EoNquPmoYsk2PxKpcfxVWYqNgVxU7rRQ-xBxcZXziH5n9IXNNl1KKzLtUYgVRKqWRczh2wINcvDY8WuWoMpIETxWpYhIbrZ-w46xB1v2YMADbOfrFNxLhiyIC239GIQRC__Tw_KiYoZiK1A#=”

我不知道它是否还给我一些东西。 我想要的是我能够在我的facebook页面上发布“ hello world”。这是我的php代码。

require_once('facebook.php');


$config = array(
'appId' => 'xxxxx',
'secret' => 'xxxxxxxxxx',
'cookie' => 'true'
  );

$facebook = new Facebook($config);
$user_id = $facebook->getUser();

$user_profile=null;  

if($user_id) 
{

  try 
  {
        $user_profile = $facebook->api('/me');
        $facebook->api('/me/feed','post',array(
        'message'=>'hello world'
        ));

  } 
  catch(FacebookApiException $e) 
  {
        echo $e->getMessage();
  }   

}

if($user_id)
{
    $logout_url=$facebook->getLogoutUrl();  
    echo "<a href='$logout_url'>Logout</a>";
}
else
{
    $login_url=$facebook->getLoginUrl(array(
    'scope'=>'read_friendlists,publish_stream,email,user_work_history,user_website,user_religion_politics,user_relationship_details,user_relationships,user_interests,user_hometown,user_education_history,user_birthday,user_about_me'
    ));
    echo "<a href='$login_url'>Login</a>";

}

毛扎姆

这段代码对我有用-请查看PHP SDK中的examples文件夹

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

// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
  'appId'  => '350881691595504',
  'secret' => 'a50ae255f0ba3c24000e38ede7f666b9',
));

$user = $facebook->getUser();

if ($user) {
  try {
    $response = $facebook->api('/me/feed','post',array(
      'message'=>'hello world'
    ));
  } 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 {
  $loginUrl = $facebook->getLoginUrl();
}

?>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
  <head>
    <title>PHP SDK TEST</title>
  </head>
  <body>
    <?php if ($user): ?>
      <a href="<?php echo $logoutUrl; ?>">Logout</a>
    <?php else: ?>
      <div>
        Login using OAuth 2.0 handled by the PHP SDK:
        <a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
      </div>
    <?php endif ?>

    <?php if ($user): ?>
      <h3>Hello World Result</h3>
      <pre><?php print_r($response); ?></pre>
    <?php else: ?>
      <strong><em>You are not Connected.</em></strong>
    <?php endif ?>
  </body>
</html>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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