FB.ui apprequest,获取所选用户ID

时间:2011-04-08 10:12:33

标签: facebook

如何检索在“应用程序请求”对话框生成的多朋友选择器中检查的用户标识?我试过了:

FB.ui({ method: 'apprequests',
        message: 'Here is a new Requests dialog...'
    }, function (response) {
        if (response && response.request_ids) {
            console.log(response.request_ids);
        } 
    });

但我在控制台中没有得到任何结果。感谢

6 个答案:

答案 0 :(得分:3)

这是我的代码。

FB.ui({ 
  method: 'apprequests',
  message: 'Here is a new Requests dialog...' 
}, function(res){
  if (!res || !res.request_ids) { /* user canceled */ return; }
  var req_ids = res.request_ids;
  var _batch = [];
  for(var i=0; i<req_ids.length; i++ ){
    _batch.push({"method":"get","relative_url":req_ids[i]});
  }
  if(_batch.length>0){
    FB.api('/','POST',{batch:_batch},function(res){
      //res contains uids.
    });
  }
});

答案 1 :(得分:3)

这是一篇关于如何在PHP中获取请求对象以及如何从请求对象中获取信息的文章。 http://denverapps.co/list-of-user-ids-from-requests-dialog-migrating-from-fb-request-form-to-fb-ui-apprequests-facebook-api-javascript-php

答案 2 :(得分:2)

request_ids不再存在,只想发布最新代码

FB.ui({
    method: 'apprequests',
    message: "my app request message",
    picture: 'url to my image',
    max_recipients: 'number of recipients in integer (max 50, 30 for IE6/7)'
}, function(response) {
    if(response && response.hasOwnProperty('to')) {
        for(i = 0; i < response.to.length; i++) {
            console.log("" + i + " ID: " + response.to[i]);
        }
    }
});

答案 3 :(得分:1)

在我正在处理的应用中

response.request_ids

不再存在。
它似乎现在使用

response.to

它为我提供了用户ID,而不是请求ID。请求ID无处可寻,但对我来说没关系,因为我想要用户ID:)

以下是我的响应对象在检查器中的样子

Object
    request: 12345678909876
    to: Array[2]
    __proto__: Object

<强>更新
我刚刚在Facebook API文档中找到了这个。它说明了我上面所说的内容 事实证明,有一个Requests 2.0 API

http://developers.facebook.com/docs/reference/dialogs/requests/
在标题下Updated Request ID Format

答案 4 :(得分:1)

继承人新的回应。感谢pferdefleisch

代码
FB.ui({
    method: 'apprequests',
    message: "Test",
    data: "whatever"
}, function (response) {
    if (response && response.to) {
        for (var j = 0; j < response.to.length; j++) {
            alert(response.to[j]);
        }
    }
});

答案 5 :(得分:0)

我尝试了相同的代码..... 首先,“response.request_ids”为您提供请求ID而不是用户ID FB.api('/ me / apprequests /?request_ids ='为您提供与request_ids相关的数据.. 但在我的情况下,问题是我得到一个朋友的随机用户ID,我甚至没有选择

 FB.ui({
     method: 'apprequests',
     message: 'You should learn more about this awesome game.', data: 'tracking information for the user'
   },function(response) {
    if (response && response.request_ids) {
       //alert(typeof(response.request_ids));
       //alert(response.request_ids);
       alert (response.request_ids);
       len=response.request_ids.length;
       alert(len);
        if (len>2) {
               alert("Select no more than one friend");
        }
        else {
             user_req_id = response.request_ids[0];
             alert (user_req_id);
             FB.api('/me/apprequests/?request_ids='+toString(user_req_id),
                function(response) { 
                    alert(response);
                    alert(response['data'][0]['from']['id']); 
                });
                }
        } 
    else {
       alert('Post was not published.');
     }
   });
相关问题