2

我编写了以下方法来检查用户是否在网页上提交了 3 个自定义打开图形操作中的任何一个:

function checkOpenGraphHistory()
{
    var actionList = new Array($('#fb1').attr("data-action"), $('#fb2').attr("data-action"), $('#fb3').attr("data-action"));
    var nameList = new Array($('#fb1').attr("data-name"), $('#fb2').attr("data-name"), $('#fb3').attr("data-name"));
    var idList = new Array('#fb1', '#fb2','#fb3');
    var i = 0;

    while(i < actionList.length)
    {
    FB.api('me/' + actionList[i] + '/?fields=id&object=' + location.href,
       function (checkResponse)
       {
           --i; //the callbacks seem to be added to a queue instead of being processed per api request. Without this line, i always = actionList.length.
           if (!checkResponse)
           {
               console.log('Check: Empty response checking: ' + checkResponse.error.message);
           }
           else if (checkResponse.error)
           {
               console.log('Check: ERROR checking: ' + checkResponse.error.message);
           }
           else if (checkResponse.data.length < 1)
           {
               console.log('Check: User has not ' + nameList[i] + ' this item before.');
           }
           else
           {
               console.log('Check: User ' + nameList[i] + 'ed item before, ID: ' + checkResponse.data[0].id + " actionList.length: " + actionList.length + "and i is: " + i);
           }
       }  );
       i++;
    }
}

这会执行 3 个 HTTP 请求,并且返回的结果的准确性不是 100%。所以,我要么想把它变成一个批处理请求、FQL 请求,要么我想通过 API 查询网页/对象并返回所有操作(目前 3 个自定义操作,一个内置操作,2 个是自定义操作)当前用户在此网页/对象上执行。

这样的事情会很好:

https://graph.facebook.com/me/ {appNameSpace}:{action}/{object}

但是我想检查多个动作,我现在想检查一个对象上的至少 3 个动作,将来可能会检查更多动作。

我尝试使用带有参数的Graph API 资源管理器:

me/?batch=[{"method":"GET", "relative_url":"me/myNamespace:myAction/", "object":"objectURL"}]

me/?batch=[{"method":"GET", "relative_url":"me/myNamespace:myAction/", "body":"url=objectURL"}]

但是,这会返回针对此特定对象/url 的自定义操作的多个实例,而不仅仅是有关针对该特定对象的特定操作的信息。用户每个对象只能执行一次唯一操作(一对一关系),但可以执行所有三个操作一次,所以我只想每个操作返回一个结果,特别是用户是否对指定对象执行了指定操作.

4

0 回答 0