FB.api“ / me / apprequests /?request_ids =” + ids返回空数据

问题描述

| 我正在使用javascript SDK向朋友发送一些邀请,我希望获得朋友的ID。这是我的代码的一部分:
 function RequestFriendship() {
        FB.getLoginStatus(function (response) {
            if (response.session && response.perms != null && response.perms.indexOf(\'user_about_me\') != -1) {
                Request();

            }
            else {
                FB.ui({
                    method: \'auth.login\',perms: \'user_about_me,publish_stream\',display: \'iframe\'
                },function (response3) {
                    if (response3 != null && response3.perms != null && response3.perms.indexOf(\'user_about_me\') != -1) {

                        Request();

                    }
                    else {
                        alert(\'No invitations sent.\');
                    }
                });
            }
        });
而我的Request方法是:
 function Request() {

        FB.ui({ method: \'apprequests\',message: \'Mensaje Publicidad\',data: \'\',title: \'Titulo publicidad\' },function (response) {

                if (response && response.request_ids) {
                    var ids = response.request_ids;

                    FB.api(\"/me/apprequests/?request_ids=\" + ids[0],function (response2) {
                        alert(JSON.stringify(response2,replacer));

                    });

                }
            });
    }
但是每次运行它时,我都会在FB.api(\“ / me / apprequests /?request_ids = \” + ids [0]中得到一个空数据。以前但现在不是。这是权限问题吗?我认为user_about_me足以要求进行申请,但现在还不确定,有什么帮助吗?     

解决方法

我会自己找到答案的。只需使用此:
                if (response && response.request_ids) {
                    var ids = response.request_ids;

                    var _batch = [];
                    for (var i = 0; i < ids.length; i++) {
                        _batch.push({ \"method\": \"get\",\"relative_url\": ids[i] });
                    }
                    if (_batch.length > 0) {
                        FB.api(\'/\',\'POST\',{ batch: _batch },function (res) {
                            // var obj = eval(\'(\' + res + \')\');

                            for (var j = 0; j < res.length; j++) {
                                body = res[j].body;
                                var myObject = eval(\'(\' + body + \')\');
                                friendID = myObject.to.id;
                               // here you have every friendID

                            }
                        });
                    }

                }
:)     ,您实际上不需要创建批处理请求。您可以在根目录上使用ids参数,并直接为其提供从对话框返回的
request_ids
值:
FB.api(\"/?ids=\" + response.request_ids,callback);