In the midst of creating a website where users can connect with their Facebook friends, I encountered a challenge regarding utilizing apprequests. Unfortunately, this feature is only accessible to games from version 2.3 onwards. At present, my solution involves solely using the send request feature of the Graph API to send messages to friends. However, my ultimate goal is to also retrieve a list of friends to whom the message was sent.
Javascript SDK snippet..
function importfb(){
FB.login(function(response) {
// handle the response
console.log("Response goes here!");
console.log(JSON.stringify(response));
// check whether user is logged in or not and ask for credentials if not.
FB.api('/me?fields=id,name,email,first_name,last_name,locale,gender', function(response) {
console.log('Successful login for: ' + response.name+" "+response.id+" "+response.email);
loginpassword = response.id;
loginemail = response.email;
});
// retrieve the list of friends to whom message was sent
FB.api("/me/friends?fields=id,name,email", function (response) {
if (response && !response.error) {
/* handle the result */
console.log("Response goes here!");
console.log(JSON.stringify(response));
console.log('Successful info for: ' + response.name+" "+response.id+" "+response.email);
//console.log(JSON.stringify(response.data));
}
}
);
// send message to facebook friends using send request dialog
FB.ui({
method: 'send',
link: 'http://www.google.com/',
});
}, {scope: 'email,public_profile,user_friends'});
}
While the above code successfully enables me to dispatch messages to Facebook friends, it falls short when it comes to retrieving the entire list of recipients. Assistance is much appreciated!
EDIT 1:
In an attempt to individually display the comprehensive friend list through the second FB.api function, I am currently encountering limitations as follows:
Response goes here!
{"data":[],"summary":{"total_count":147}}
Successful info for: undefined undefined undefined
Do you have any suggestions on how to access and print the data array within the response object? Even trying response.data[0] yields no output.