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

发布于 2024-11-09 11:01:30 字数 1627 浏览 0 评论 0原文

我使用 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.');
                    }
                });
            }
        });

我的请求方法是:

 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 足以请求 apprequest,但不确定有什么帮助吗?

Im using javascript SDK to send some invitations to friends, and i neeed to get the friends IDs. this is part of my code:

 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.');
                    }
                });
            }
        });

and my Request method is:

 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));

                    });

                }
            });
    }

But every time run it i get an empty data in the FB.api("/me/apprequests/?request_ids=" + ids[0]. I dont know what im doing wrong, i think i worked fine for me some time ago but now it isnt. Is this a permission problem? I think user_about_me is enough to ask for apprequest but not sure anymore. Any help? Thanx

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

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

发布评论

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

评论(2

恋竹姑娘 2024-11-16 11:01:30

我自己找到了答案。就用这个:

                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

                            }
                        });
                    }

                }

:)

WEll i found the answer myself. Just use this:

                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

                            }
                        });
                    }

                }

:)

染墨丶若流云 2024-11-16 11:01:30

您实际上不需要创建批量请求。您可以在根目录上使用 ids 参数,并直接为其提供从对话框返回的 request_ids 值:

FB.api("/?ids=" + response.request_ids, callback);

You don't actually need to create a batch request. You can use the ids parameter on the root and give it the request_ids value returned from the dialog directly:

FB.api("/?ids=" + response.request_ids, callback);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文