facebook JS SDK批量请求自定义操作

时间:2012-12-27 09:43:36

标签: facebook api object batch-file opengraph

我编写了以下方法来检查用户是否在网页上提交了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个自定义动作,一个是内置动作,另外两个是自定义动作)当前用户在此网页/对象上执行。

这样的事情会很好:

https://graph.facebook.com/me/ {appNameSpace}:{动作} / {对象}

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

我尝试将Graph API explorer与参数:

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

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

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

0 个答案:

没有答案
相关问题