被困在 Facebook 上发帖

发布于 2024-11-03 17:27:36 字数 1039 浏览 0 评论 0原文

我是 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 中抛出错误签名

我错过了什么吗?

I'm new in facebook apps development and I'm get stuck on how to post to facebook.
I've read tutorials, and do according to them.

Here is the code :

<?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);

?>

Result:
Fatal error: Uncaught OAuthException: Bad signature thrown in C:\wamp\www\facebook\examples\facebook.php on line 543

Did I miss something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半葬歌 2024-11-10 17:27:36

好的,您正在使用原始 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 将自行处理令牌;)

Ok, you are using raw OAuth login and at the same time using facebook php SDK.
Don't do it like that, if you are using SDK us it all the way:

<?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 will handle token him self ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文