如何在Facebook请求对话框中获取用户ID [英] how to get user id on facebook request dialog
问题描述
我想做的是获取请求ID并插入到我的数据库。我的请求对话框运行良好,但问题是我无法获取'TO'用户标识 http ://developers.facebook.com/docs/reference/dialogs/requests/ ,但我仍然无法获取请求用户ID。
这是我的代码:
function newInvite(){
// var user_ids = document.getElementsByName(user_ids)[0] .value;
FB.ui({
method:'apprequests',
title:'X-MATCH',
message:'Come join US now,fun fun here',
函数getMultipleRequests(requestIds){
FB.api('',{ids:requestIds},function(response){
console.log(response);
});
}
);
}
任何解决方案?
/ p>
$ b
您是否启用请求2.0? $ b
如果您已启用,您可以轻松获取用户ID作为此类回复
{
请求:'request_id'
to:[array of user_ids]
}
在您的回调函数中,您可以使用
response.request
获取请求ID
response.to
获取用户ID的数组
并注意如果您使用请求2.0,请求ID格式将这样
< request_object_id> _< user_id>
如果您不启用它,那么您只能获取请求ID数组,您需要编辑:
<$ p $($)
p>
FB.ui({
method:apprequests,
title:your title,
message:your msg
}
函数(响应){
var receiverIDs;
if(response.request){
var receiverIDs = response.to; // receiverIDs是一个包含所有用户ID的数组
}
}
);
然后,您可以使用数组receiverIDs进一步处理
例如,我发送了一个请求,用户ID为1234,5678
响应将如下所示:
{
request:'1234567890'// example,
to:['1234','5678']
}
在请求2.0中,完整的请求ID将如下所示
1234567890_1234
1234567890_5678
注意:FB文档告诉您自己管理和删除请求,如果您使用请求2.0,
请记住删除如上所述的ID,如果直接删除请求123456789,所有完整请求具有此前缀的ID将被删除。
=======================
如果您尚未启用请求2.0,请按照文档页面上的代码查看如何获取用户ID api调用
函数getMultipleRequests(requestIds){
FB.api('',{ids:requestIds} ,function(response){
console.log(response);
});
}
这些方法的响应格式如下:
{
id:[request_id],
application:{
name [申请名称],
id:[申请ID]
},
to:{
name:[收件人用户名] ,
id:[收件人用户ID]
},
from:{
name:[Sender User ID],
id:[发件人用户名]
},
消息:[请求消息],
created_time:2011-09-12T23:08 :47 + 0000
}
你可以实现api调用的回调,是 response.to.id的接收者
What i want to do is get the request ID and insert to my database. My request dialog is run well, but the problem is I cannot get 'TO' user id http://developers.facebook.com/docs/reference/dialogs/requests/ , but I still cannot get the request user ID.
here is my coding:
function newInvite(){
//var user_ids = document.getElementsByName("user_ids")[0].value;
FB.ui({
method : 'apprequests',
title: 'X-MATCH',
message: 'Come join US now, having fun here',
},
function getMultipleRequests(requestIds) {
FB.api('', {"ids": requestIds }, function(response) {
console.log(response);
});
}
);
}
any solution on this?
million thanks for help
Have you enable request 2.0 efficient?
If you have enabled, you can get the user id easily as the response like this
{
request: ‘request_id’
to:[array of user_ids]
}
In your callback function, you can use
response.request
to get the request ID
response.to
to get the array of user ids
And notice that if you use request 2.0, the request ID format will like this
<request_object_id>_<user_id>
If you doesn't enable it, then you can only get the array of request ids and you need to make another api call to get the user id
Edited:
FB.ui({
method : "apprequests",
title : "your title",
message : "your msg"
},
function(response) {
var receiverIDs;
if (response.request) {
var receiverIDs = response.to; // receiverIDs is an array holding all user ids
}
}
);
Then you can use the array "receiverIDs" for further process
For example I sent a request to user id with id "1234", "5678"
The response will like this:
{
request: ‘1234567890’ // example,
to:['1234', '5678']
}
In request 2.0, the full request id will look like this
1234567890_1234
1234567890_5678
Caution: FB doc tell you to manage and delete the request yourself, if you using request 2.0, remember to delete the id like the above, if you directly delete the request '123456789', all the full request ID with this prefix will be deleted.
==================================================================
If you haven't enable request 2.0, follow the code on the doc page to see how to get the user id by making a api call
function getMultipleRequests(requestIds) {
FB.api('', {"ids": requestIds }, function(response) {
console.log(response);
});
}
The response format for these methods is as follows:
{
"id": "[request_id]",
"application": {
"name": "[Application Name]",
"id": "[Application ID]"
},
"to": {
"name": "[Recipient User Name]",
"id": "[Recipient User ID]"
},
"from": {
"name": "[Sender User ID]",
"id": "[Sender User Name]"
},
"message": "[Request Message]",
"created_time": "2011-09-12T23:08:47+0000"
}
you can implement the callback of api call and getting who is the receiver by response.to.id
这篇关于如何在Facebook请求对话框中获取用户ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!