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

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;

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 Most Mutual Friends

I am trying to find the friends with most mutual friends with me.
public function topThreeMutualFriends() {
$count;
$query='select uid1 from friend where uid1 in (select uid2 from friend where uid1=me()) and uid2 in (Select uid2 from friend where uid1=me()) and uid1!=uid2';
$result = $this->api(array('query' => $query , 'method' => 'fql.query'));
if(!$result)
throw new exception("No Mutual Friends");
else{
foreach ($result as $uid)
$count[$uid['uid1']]++;
arsort($count, SORT_NUMERIC);
$i=0;
foreach($count as $key=>$uid){
$topthree[$i++]=$key;
if($i==3)break;
}
return array($topthree,$count);}
}
In the above code an exception is raised stating:"This API call could not be completed due to resource limits"
I tried giving all the permissions, and the query works fine in the fql tester.
What could be the possible reason??
That's pretty complex code. Why not just let FQL find your top three friends with the most mutual friends?
$query = 'SELECT uid, name, mutual_friend_count
FROM user WHERE uid IN
(SELECT uid1 FROM friend WHERE uid2 = me())
ORDER BY mutual_friend_count DESC LIMIT 3';
The possible reason is the error message you pasted, your query is too expensive in terms of the resources needed from Facebook's side.
Break it up into smaller queries and do that instead. For example, fetch the list of friends in one call, split the list into smaller chunks, and check the mutual friends count for the batches in separate calls.

How to get friends name in fql

I am executing this query in FQL [#"SELECT likes,message,actor_id FROM stream WHERE source_id = %lld limit 50", _session.uid]. It is giving result well but I want to fetch my friends name also. I don't want to execute query within loop to fetch friends name from their profile. If it is possible in multiquery then which type of query I will have to write?
I use this code:
NSString* fql = [NSString stringWithFormat:#"SELECT uid,name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = %lld)", session.uid];
Hope it can give you a hint.

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*}

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!