使用 PHP5 Curl 调用 Facebook Graph API。不同的服务器得到不同的响应

发布于 2024-11-01 02:07:14 字数 1473 浏览 0 评论 0原文

我有一个 PHP 应用程序,它使用 Curl 调用 Facebook Graph API 并将项目发布到用户的墙上。它在我的开发盒和生产服务器上运行良好,但在一台 QA 服务器上不起作用。我们收到了一个模糊的错误代码 100:“消息失败”。据我所知,我从所有服务器发送相同的信息。

这是我对开发框的请求:

Array
(
    [0] => Accept: text/html,application/xhtml+xml,application/xml;q=0.9;q=0.8
    [1] => Accept-Language: en-us,en;q=0.5
    [2] => Accept-Charset: utf-8;q=0.7,*;q=0.7
)
POST: https://graph.facebook.com/me/feed
{
    "message":"my message",
    "picture":"http:\/\/server.com\/image.jpeg",
    "link":"http:\/\/server.com\/page",
    "name":"foo",
    "caption":"bar",
    "access_token":"{ACCESS_TOKEN}"
}

这是响应(有效):

{
   "id": "6705254_873254004878"
}

这是我对 QA 框的请求(相同的 ACCESS_TOKEN)

Array
(
    [0] => Accept: text/html,application/xhtml+xml,application/xml;q=0.9;q=0.8
    [1] => Accept-Language: en-us,en;q=0.5
    [2] => Accept-Charset: utf-8;q=0.7,*;q=0.7
)
POST: https://graph.facebook.com/me/feed
{
    "message":"my message",
    "picture":"http:\/\/server.com\/image.jpeg",
    "link":"http:\/\/server.com\/page",
    "name":"foo",
    "caption":"bar",
    "access_token":"{ACCESS_TOKEN}"
}

<强>这是对质量检查的回应(失败)

{
   "error": {
      "type": "OAuthException",
      "message": "(#100) Message Failed"
   }
}

我已经删除了我们发送的图片和链接的实际网址,但你明白了:)

有人知道我可能做错了什么吗?在我看来是一样的......

I have a PHP app that uses Curl to call the Facebook Graph API and post items to a user's wall. It works great on my dev box and our production servers, but it doesn't work on one QA server. We're getting a nebulous error code 100: "Message Failed" back. As far as I can tell, I'm sending the same information from all servers.

Here's my request on the dev box:

Array
(
    [0] => Accept: text/html,application/xhtml+xml,application/xml;q=0.9;q=0.8
    [1] => Accept-Language: en-us,en;q=0.5
    [2] => Accept-Charset: utf-8;q=0.7,*;q=0.7
)
POST: https://graph.facebook.com/me/feed
{
    "message":"my message",
    "picture":"http:\/\/server.com\/image.jpeg",
    "link":"http:\/\/server.com\/page",
    "name":"foo",
    "caption":"bar",
    "access_token":"{ACCESS_TOKEN}"
}

Here's the response (it works):

{
   "id": "6705254_873254004878"
}

Here's my request on the QA box (same ACCESS_TOKEN):

Array
(
    [0] => Accept: text/html,application/xhtml+xml,application/xml;q=0.9;q=0.8
    [1] => Accept-Language: en-us,en;q=0.5
    [2] => Accept-Charset: utf-8;q=0.7,*;q=0.7
)
POST: https://graph.facebook.com/me/feed
{
    "message":"my message",
    "picture":"http:\/\/server.com\/image.jpeg",
    "link":"http:\/\/server.com\/page",
    "name":"foo",
    "caption":"bar",
    "access_token":"{ACCESS_TOKEN}"
}

Here's the response on QA (fail)

{
   "error": {
      "type": "OAuthException",
      "message": "(#100) Message Failed"
   }
}

I have removed the actual URLs we're sending for picture and link, but you get the idea :)

Does anyone know what I could be doing wrong? It looks the same to me....

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

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

发布评论

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

评论(2

哆啦不做梦 2024-11-08 02:07:14

嘿,
我认为这是您的应用程序设置中给出的站点 URL 的问题。 Facebook 仅允许来自应用程序设置中列出的域的请求。

Hey,
I think its a problem with the Site URL given in your app settings. Facebook only allows requests from the domain listed in your application settings.

公布 2024-11-08 02:07:14

据我了解 Facebook 政策,只有一个客户端可以使用特定的访问令牌进行授权 - 因此您应该在发布之前获取一个新的。此处进行了描述: Facebook:“此授权码已被使用.","type":"OAuthException","code":100

所以你应该添加

$access_token = $session->getToken();

As far as I understood facebook policy, only one client can authorise with particular acess token - so you should get a new one before posting. It was described here: Facebook: "This authorization code has been used.","type":"OAuthException","code":100

So you should add

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