首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FB.api("/me/apprequests/?request_ids="+ids)返回空数据

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

Stack Overflow用户
提问于 2011-05-26 04:29:07
回答 2查看 7.3K关注 0票数 0

我正在使用javascript SDK向朋友发送一些邀请,我需要获得朋友的ID。这是我的代码的一部分:

代码语言:javascript
复制
 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.');
                    }
                });
            }
        });

我的请求方法是:

代码语言:javascript
复制
 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.我不知道我做错了什么,我想我以前做得很好,但现在不是了。这是权限问题吗?我认为user_about_me已经足够提出请求了,但现在不再确定了。有什么帮助吗?谢谢

EN

回答 2

Stack Overflow用户

发布于 2011-05-27 00:29:00

WEll我自己找到了答案。只需使用以下命令:

代码语言:javascript
复制
                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

                            }
                        });
                    }

                }

:)

票数 1
EN

Stack Overflow用户

发布于 2011-06-10 17:50:40

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

代码语言:javascript
复制
FB.api("/?ids=" + response.request_ids, callback);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6130493

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档