FB.api对组的POST返回GET 500(内部服务器错误)

FB.api POST to a group is returning GET 500 (Internal Server Error)

本文关键字:内部 服务器 错误 GET 返回 api POST FB      更新时间:2023-09-26

我知道这一定是一件简单的事情,但就我的一生而言,我无法通过检查我的代码或使用谷歌来获得可能原因的帮助来找到答案!

这是我桌子的照片:

(图片会放在这里,但显然我必须至少有10个声誉才能发布图片?)

图片描述:一个简单的HTML表,有一个Header行和与我所属的Facebook群组一样多的后续行。共有5列:图标、名称、电子邮件、ID,以及用于删除特定行的按钮的一列。

表结构和数据是使用JavaScript函数动态构建的。

以下是我的JavaScript函数,它形成并处理对FB.api的调用:

function postMessage() {
groupsTbl = document.getElementById("groupsTbl");
msgSubject = document.getElementById("msgSubject");
msgBody = document.getElementById("msgBody");
msgPic = document.getElementById("msgPic");
FB.getLoginStatus(
    function(response) {
        if (response.status === 'connected') {
            for (var i = 1; i < groupsTbl.rows.length; i++) {
                row = groupsTbl.rows[i].cells;                  
                /* make the API call */
                FB.api(
                    "/" + row[3].innerHTML + "/feed",
                    "POST",
                    { "object": { "message": "this is a test" } },
                    function (response) {
                        if (response && !response.error) {
                            console.log(response);/* handle the result */
                        }
                        else
                            console.log(response);/* handle the result */
                    }
                );
            }
        } else if (response.status === 'not_authorized') {
        // the user is logged in to Facebook, 
        // but has not authenticated your app
        } else {
        // the user isn't logged in to Facebook.
        }
    }
);
}

结果是这样的

正如您从屏幕截图顶部看到的,ID已成功检索并打印到控制台以进行调试。GET的ID似乎是正确的,但显然出了问题!

(图片会放在这里,但显然我必须至少有10个声誉才能发布图片?)

图像描述:

126566634108032 (index):123
GET https://graph.facebook.com/157375201005164/feed?access_token=CAAVK9GATPtMBA…&object=%7B%22message%22%3A%22this%20is%20a%20test%22%7D&pretty=0&sdk=joey 500 (Internal Server Error) debug.js:6245
Object {error: Object}
error: Object
message: "unknown error"
type: "http"
__proto__: Object
__proto__: Object

查看https://developers.facebook.com/docs/javascript/reference/FB.api/#examples有一个Example: Publish a status message to the current user's feed:

FB.api('/me/feed', 'post', { message: body }, function(response) {
  if (!response || response.error) {
    alert('Error occured');
  } else {
    alert('Post ID: ' + response.id);
  }
});

转移到你的代码,这将在中产生

FB.api(
    "/me/feed",
    "POST",
    { message: "this is a test" },
    function (response) {
        if (response && !response.error) {
            console.log(JSON.stringify(response));
        }
        else
            console.log(JSON.stringify(response.error));
    }
;