Get fql result into variable - facebook-fql

i'm trying to get fql (facebook query) my facebook friends that using my app result into a variable, with javascript.
i was trying to do something like this, but unfortunately it doesn't work:
FB.api('/me', function(user) {
var fx = "";
this.query = FB.Data.query('SELECT uid FROM user WHERE uid IN ' + '(SELECT uid2 FROM friend WHERE uid1 = me()) AND is_app_user');
this.query.wait(function(rows) {
fx = rows[0].uid;
});
});
alert(fx);
if the alert was inside of the query wait it worked, but i need this into a variable.
thanks for helping.

that's because var fax=""; is inside the block. try to put that outside the block.
var fx = "";
FB.api('/me', function(user) {
this.query = FB.Data.query('SELECT uid FROM user WHERE uid IN ' + '(SELECT uid2 FROM friend WHERE uid1 = me()) AND is_app_user');
this.query.wait(function(rows) {
fx = rows[0].uid;
});
});
alert(fx);

Related

Get Female Friends facebook

I want to get female friends facebook
$fql = "https://graph.facebook.com/me/fql?q=SELECT sex, uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND sex = 'female' LIMIT 10&access_token=$access_token";
$fqlresult = file_get_contents($fql);
$f = json_decode($fqlresult, true);
$friends1 = $f['data']['1']['uid'];
I tried this but not returning anything.
You can try using graph api to get friends gender and filter using php code to get female friends:
$query = "https://graph.facebook.com/v2.1/me?fields=friends{gender,name}&acess_token=$your_access_token";
$results = file_get_contents($query);
$freinds = json_decode($results , true);
foreach($freinds as $friend)
{
if($friend['gender']=='female')
{
echo $friend['name'].'<br>';
}
}
The FQL query SELECT sex, uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND sex = 'female' LIMIT 10
is correct and works (I tried it), your overall API query needs to be something like
https://graph.facebook.com/fql?q=
not
https://graph.facebook.com/me/fql?q=
remove me

Facebook SDK Unity. how to get a list of friends who play this game?

How to get a list of friends who play in my game or who install my game?
This code is not working:
string fql = "/fql?q=SELECT uid, name, is_app_user, pic_square FROM user WHERE uid IN "+
"(SELECT uid2 FROM friend WHERE uid1 = me()) AND is_app_user = 1";
FB.API(fql, Facebook.HttpMethod.GET, GetListOfPlayer);
You're query is absolutely correct. I'm not sure but the problem could be that you have not urlencoded the fql query.
You can try this-
string query = WWW.EscapeURL("SELECT uid, name, is_app_user, pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND is_app_user = 1");
string fql = "/fql?q="+query;

Facebook fql.query Syntax

I'm trying to properly understand the syntax for Facebook's fql.query. The context for this query is to get all the mutual friends between two users. Using an example of "user1 = dusty24" and "user2 = april1991" what would the values for the following vars be?
uid1
uid2
source_uid
target_uid
It's pretty safe to assume that 'uid1 = dusty24' and 'uid2 = april1991' but what the heck are the values for 'source_uid' and 'target_uid'?
FB.api(
{
method: 'fql.query',
query: 'SELECT uid1 FROM friend WHERE uid1 IN (SELECT uid2 FROM friend WHERE uid1=source_uid) AND uid2=target_uid'
},
function(response) {
console.log(response);
}
}
I took a quick read through the documentation, it tells us uid1 is the user id of the first user of the pair and uid2 is the second user of the pair. These are fields from the table. You don't change these in the query. You would end up with source_uid and target_uid be the user ID's of each of those people.
Assuming your query works correctly. You would end up looking something like this. Note: you would need to get the user id of your two users before hand.
SELECT uid1 FROM friend
WHERE uid1 IN
( SELECT uid2 FROM friend WHERE uid1={*dusty24 uid*} )
AND uid2={*april1991 uid*}

FQL to get Online Friends return zero

I am trying to get Online Friends by using following code.
protected void GetActiveFriends()
{
var fb = new FacebookWebClient();
dynamic myInfo = fb.Get("me");
var uId = myInfo.id;
dynamic friends = fb.Query("SELECT uid, name, pic_small, online_presence FROM user WHERE online_presence IN ('active', 'idle') AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me())");
Response.Write(friends.Count);
foreach (dynamic friend in friends)
{
Response.Write(friend.id);
}
}
friends.Count returns Zero & none of the friend.id gets displayed.
I guess my query is right then what's the problem.
Never mind got it. Had not added extra permissions.

Starting multiquery in client throws parser error

I have a following problem in c# SDK: when I try to run multiquery in my desktop application with following string (searching for pairs of IDs of mutual friends) I get a parser error:
string strCommonFriendsQuery = "{
\"user_friends\":\"SELECT uid2 FROM friend WHERE uid1 = me()\",
\"mutual_friends\":\"SELECT uid1, uid2 FROM friend WHERE uid1 IN (SELECT uid2 FROM #user_friends) AND uid2 IN (SELECT uid2 FROM #user_friends)\"
}";
fb.Query(strCommonFriendsQuery);
Parser error: unexpected '{' at position 0.
The same string (without the escape sequences before quotation marks) works if I paste it to
http://developers.facebook.com/docs/reference/rest/fql.multiquery/
but not in
http://developers.facebook.com/docs/reference/rest/fql.query/
so the problem is that I need to launch it as multiquery and not as a query - now what I would like to ask is:
Is it possible to somehow process multi-query using the Facebook.FacebookClient.Query function of the SDK or do I have to write a function which would do that? As I understand the only thing I would need to change is the address to which it connects to. If so, could it be added in the next SDK version?
Here is an alternate to firepol's answer, with named queries:
var queries =
new Dictionary<string, object>
{
{ "FamDamly", "select uid from family where profile_id = me()" },
{ "FamDetails", "select uid, first_name from user where uid in #FamDamly" }
};
client.Get(queries);
To do a multiquery with a reference to the first query, such as the one in the question, do as follows:
//note: queries begin from 0, not from 1
string query0 = "SELECT uid2 FROM friend WHERE uid1 = me()";
string query1 = "SELECT uid1, uid2 FROM friend WHERE uid1 IN (SELECT uid2 FROM #query0) AND uid2 IN (SELECT uid2 FROM #query0)";
dynamic result = fb.Query(query0, query1);
To answer this, I got inspired from here (had to figure out that queries start from 0): How to use fql.multiquery with C# SDK
Enjoy!