I have a Users with friends:
User {
"#rid:": "#11:2"
...
friends: ["#61:1", "#61:2", "#61:3"]
}
...
User {
"#rid:": "#11:3"
...
friends: ["#61:2", "#61:3","#61:4"]
}
How i can to find joint friends of users ("#11:2", "#11:3") with osql?
So query should return "#61:2", "#61:3".
Try this:
select from User where #rid in (select out() from User where #rid = "#11:2") and #rid in (select out() from User where #rid = "#11:3")
Hope it helps
Regards
Related
I have SQL this query:
SELECT f.follower_id, u.fname, u.lname
FROM followers f
INNER JOIN users u ON f.follower_id = u.id
WHERE f.user_id = $user_id
AND u.status = 1
ORDER BY fname, lname
LIMIT 10
I have two models: User and Follower.
A user can have many followers, and each follower has its own user data. I want to be able to get all of a user's followers (who have a status of 1) by doing something like this:
$followers = User::get_followers();
Add this to your User model:
public function followers()
{
return $this->belongsToMany(User::class, 'followers', 'user_id', 'follower_id')
->where('status', 1)
->orderBy('fname')
->orderBy('lname');
}
Then you can access them like this:
$followers = $user->followers;
I'm creating a javascript facebook app to have an overview of my friendlists. Actually I can retrieve my (logged in user = me) friendlists, when I click a friendlist I see all my friends in that list.
When I want now is, when I click a list, I want to see the friends belonging to that list, and a comma separated lists my friend is member of.
For example in the list "Best" I have 3 friends: Athos, Portos, Aramis. But they are also in other lists. So in my app I'd like to get something like this:
Athos: Best, Family, Close Friends, VIP
Portos: Best, VIP
Aramis: Best, Close Friends, Party Animals
I tried with the FQL multiquery, but it seems impossible to get what I want.
So I think I should use a Batch request, but since I don't have a lot of experience using batches here I am asking your help.
So here the FQL query I use to get friends belonging to the list. I need this, because I want to manage friends beginning from a list:
var listID = 123;//just enter a listID
var friendsInList = 'SELECT uid,username,profile_url,first_name,last_name,pic_square FROM user WHERE uid IN (SELECT uid FROM friendlist_member WHERE flid =' + listID +')';
Now I don't know how to proceed in a clean and efficient way. I have a working but inefficient solution:
//[...]FB.api call to get a response object with all my friends using the friendsInList query above
for (var i = 0; i < response.length; i++) {
friendID = response[i].uid;
//call FB.api with the following query:
var friendListMemberships = 'SELECT uid, flid, name FROM friendlist_member WHERE flid IN (SELECT flid FROM friendlist WHERE owner=me()) AND uid IN (select uid FROM friendlist WHERE flid =' + friendID;
}
the above solution works but is highly inefficient as I send a FB.api request for each friend, very slow for big lists... thus I'd like a pro user to help me putting this in a batch (a batch can have maximum 50 requests, thus I'd like to send just 1-2 requests and get back all what I need).
I know how to write a batch, here I put the structure of my code, if it can help you completing it with the second query:
var listID = _listID;
var _queryFriendsInList = 'SELECT uid,username,profile_url,first_name,last_name,pic_square FROM user WHERE uid IN (SELECT uid FROM friendlist_member WHERE flid =' + listID + ')';
var queryFriendsInList = _queryFriendsInList.replace(" ", "+");
var _queryFriendListMemberships = 'I have no idea what kind of query I can write here to get the lists my friends from queryFriendsInList are member of';
var queryFriendListMemberships = _queryFriendListMemberships.replace(" ", "+");
var searchArgs = {
access_token: FB.getAuthResponse().access_token,
batch: []
};
searchArgs.batch.push({
'method': 'GET',
'name': 'friendsInList',
'relative_url': 'method/fql.query?query=' + queryFriendsInList,
'omit_response_on_success': false
});
//here is where I need help
searchArgs.batch.push({
'method': 'GET',
'name': 'friendlistMememberships',
'relative_url': 'method/fql.query?query=' + queryFriendListMemberships,
'omit_response_on_success': false
});
FB.api("/", "POST", searchArgs,
function (response) {
//console.log("log");
}
);
I hope the question and code samples are clear enough. Thank you for helping!
You can get everything you want in one API call with a multiquery. You'll need to assemble this together on the client side with a few loops, but it shouldn't be too hard. Here's the query:
{
"all_friendlists":
"SELECT flid, owner, name FROM friendlist WHERE owner=me()",
"fl_members":
"SELECT uid, flid FROM friendlist_member WHERE flid IN
(SELECT flid FROM #all_friendlists)",
"fl_member_details":
"SELECT uid, name, username FROM user WHERE uid IN (SELECT uid FROM #fl_members)"
}
You can present everything to your user from this one API call. The #all_friendlists query gives all your user's friendlists. Once your user has selected a friendlist, then loop through #fl_members to find all the members of this list, retrieving their details from #fl_member_details. Make another loop through #fl_members to find what other lists they belong to.
Alternately, you could just mash these three lists together into a single presentation page, and use a jQuery data filtering scheme like Isotope to allow your user to sort/filter/etc. on the fly.
I am using FQL. I am using the following set of query to get info about album,
SELECT aid,src_small from photo where pid='100000244468314_1600187'
i get the following result,
{
"data": [
{
"aid": "0",
"src_small": "https://fbcdn-photos-a.akamaihd.net/hphotos-ak-ash3/545289_450190444999100_1364645489_t.jpg"
}
]
}
Then i gave the following query to get the album name and owner,
SELECT aid, owner, name, object_id FROM album WHERE aid="0"
But i get the following,
{
"data": [
]
}
Why is album id 0? and why it returns None? Please help. I am new to FQL
Try this query instead:
SELECT aid, owner, name, object_id FROM album
WHERE object_id IN
(SELECT album_object_id FROM photo where pid='100000244468314_1600187')
It looks like aid and pid fields are on their way to be deprecated in exchange for the object_id fields.
FB.api(
{
method: 'fql.query',
query: 'select uid,name from user where uid in (select uid2 from friend where uid1 ='+me.id+') AND current_location='+me.location.name
},function(data) {
alert(data);
}
iam trying to get the friends based on the current user location.But this query is not working? Is there any possible way to write this as a single query?
I need to loop all the datas to check the current location else ,but it takes time for checking it.So iam looking for single query to get the datas? Could any one help me with it?
This is just an idea,
firstly your application requires user_location and friends_location as permissions.
Why don't you modify your query to something like this
FB.api(
{
method: 'fql.query',
query: 'select uid,name,current_location from user where uid in (select uid2 from friend where uid1 ='+me.id+')
},function(data) { alert(data);
}
The idea is to get current_location of user and user's friends and then do your filtering.
Hope this helps
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.