I have the following javascript:
function graphStreamPublish(){
FB.api('/me/feed', 'post',
{
message : "1",
link : "2",
picture : "3",
name : "4",
description : "5"
},
function(response) {
if (!response || response.error){
alert('Error occured');
}else{
var x = fqlQuery();
console.log(x);
alert('Post ID: ' + response.id);
}
});
}
function fqlQuery(){
FB.api('/me', function(response) {
var query = FB.Data.query('select name, profile_url from user where uid={0}', response.id);
query.wait(function(rows) {
var x=rows[0].name;
var y=rows[0].profile_url;
return [x, y];
});
});
}
which is based on the code from:
http://thinkdiff.net/facebook/new-javascript-sdk-oauth-2-0-based-fbconnect-tutorial/
The problem is that when the function graphStreamPublish() is run this in turn also executes fqlQuery, now the returned values in graphStreamPublish shows up in the console as undefined. Please can anyone help me in getting the values from fqlQuery back into graphStreamPublish.
Please note that when I console.log(rows) in the function fqlQuery there is definitely values that are being returned from FB.
Thanks
You can’t do it this way around. You are doing:
but fqlQuery isn’t returning anything. Your return statement is in the callback, which is a completely different method:
That is why your method return is undefined. Time will pass between fqlQuery() being called, and the callback being called. You will have to do the processing you need inside the callback of fqlQuery