In the Facebook API is there a way in which I can get a user's name and surname by user id?
I am using FB API in my ASP.NET MVC application and I am using the MultiFriendSelector to let the users invite friends to my app. I need that when these friends are selected, they are saved in my database so that they can have access to my pages. This is the code I have until now.
function sendRequestToRecipients() {
var user_ids = document.getElementsByName("user_ids")[0].value;
FB.ui({
method: 'apprequests',
message: 'Join my group on CodeShare!',
to: user_ids
}, requestCallback);
}
function sendRequestViaMultiFriendSelector() {
FB.ui({
method: 'apprequests',
message: 'Join my group on CodeShare!'
}, requestCallback);
}
function requestCallback(response) {
if (response.request && response.to) {
var request_ids = [];
for (var i = 0; i < response.to.length; i++) {
var fb_id = response.to[i];
request_ids.push(fb_id);
//// here I want to get the user's names and
surnames so that I can send them along with the id's..
$.ajax({
url: '/Groups/SaveInvitedFriends',
type: 'POST',
data: { invitedFriends: request_ids }
});
}
}
}
Is there a way maybe in which the user's are saved upon accepting the request?
Thanks
In the Facebook API is there a way in which I can get a user's name and surname by user id?
I am using FB API in my ASP.NET MVC application and I am using the MultiFriendSelector to let the users invite friends to my app. I need that when these friends are selected, they are saved in my database so that they can have access to my pages. This is the code I have until now.
function sendRequestToRecipients() {
var user_ids = document.getElementsByName("user_ids")[0].value;
FB.ui({
method: 'apprequests',
message: 'Join my group on CodeShare!',
to: user_ids
}, requestCallback);
}
function sendRequestViaMultiFriendSelector() {
FB.ui({
method: 'apprequests',
message: 'Join my group on CodeShare!'
}, requestCallback);
}
function requestCallback(response) {
if (response.request && response.to) {
var request_ids = [];
for (var i = 0; i < response.to.length; i++) {
var fb_id = response.to[i];
request_ids.push(fb_id);
//// here I want to get the user's names and
surnames so that I can send them along with the id's..
$.ajax({
url: '/Groups/SaveInvitedFriends',
type: 'POST',
data: { invitedFriends: request_ids }
});
}
}
}
Is there a way maybe in which the user's are saved upon accepting the request?
Thanks
Share Improve this question asked May 21, 2013 at 22:12 BerniceBernice 2,59211 gold badges45 silver badges75 bronze badges 2- no, that's would be too obvious ... LoL – Axel Amthor Commented May 21, 2013 at 22:14
- hahaha my bad sorry! am a bit tired right now and have an assignment till 2 days! was a mistake.. I need name and surname! – Bernice Commented May 21, 2013 at 22:15
1 Answer
Reset to default 4You will need to make an API call to request the user's info. Facebook's JavaScript API docs gives the following example:
FB.api('/me', function(response) {
alert('Your name is ' + response.name);
});
(from http://developers.facebook./docs/reference/javascript/#graphapi)
me
refers to the currently logged in user. If you use a userid instead, the response
object will contain name
(full name), first_name
, last_name
(surname), and several other basic fields. For example, zuck
is the userid of Mark Zuckerberg, so using the request FB.api("/zuck", function(response) { console.log(response); });
returns the following:
Object {
first_name: "Mark"
gender: "male"
id: "4"
last_name: "Zuckerberg"
link: "https://www.facebook./zuck"
locale: "en_US"
name: "Mark Zuckerberg"
updated_time: "2013-05-09T05:12:23+0000"
username: "zuck"
}
Let me know if this makes sense or if you have any questions :)