卡在Facebook上发帖

时间:2011-04-27 08:21:33

标签: facebook facebook-graph-api

我是facebook应用程序开发的新手,我不知道如何发布到Facebook。 我已经阅读了教程,并根据它们做了。

以下是代码:

<?php

require 'facebook.php';
// Create our Application instance (replace this with your appId and secret).

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

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


//Request params
if(!($_GET['code'])) {
    header("Location:https://www.facebook.com/dialog/oauth?client_id=xxx&redirect_uri=" . urlencode("http://localhost/facebook/examples/") . "&scope=publish_stream");
    //header("Location:http://www.google.com");
     exit;
} 

$token = $_GET['code'];
echo "token " . $token


$status = $facebook->api('/me/feed', 'POST', array('message' => 'This post came from my app.', 'access_token' => $token));
var_dump($status);

?>

结果:
致命错误:未捕获OAuthException:第543行C:\ wamp \ www \ facebook \ examples \ facebook.php中引发错误签名

我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

好的,您正在使用原始OAuth登录,同时使用facebook php SDK。 如果您一直使用SDK,请不要这样做:

<?php

require 'facebook.php';
// Create our Application instance (replace this with your appId and secret).

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

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

if (!$facebook->getSession()) 
{
    header('Location: ' . $facebook->getLoginUrl(array('req_perms' => 'publish_stream')));
}
else
{
    $status = $facebook->api('/me/feed', 'POST', array('message' => 'This post came from my app.'));
    var_dump($status);
}

?>

SDK将自己处理令牌;)