我正在使用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.我不知道我做错了什么,我想我以前做得很好,但现在不是了。这是权限问题吗?我认为user_about_me已经足够提出请求了,但现在不再确定了。有什么帮助吗?谢谢
发布于 2011-05-27 00:29:00
WEll我自己找到了答案。只需使用以下命令:
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
}
});
}
}:)
发布于 2011-06-10 17:50:40
您实际上不需要创建批处理请求。您可以在根目录上使用ids参数,并直接为其提供从对话框返回的request_ids值:
FB.api("/?ids=" + response.request_ids, callback);https://stackoverflow.com/questions/6130493
复制相似问题