Get members id of private facebook group - facebook

I want to get the members id of private facebook groups using facebook api and c#. i can get users id of open facebook group please any idea.
var fb = new FacebookClient(AccessToken);
//var query = string.Format("select name from group where gid = {0}", name);
var query = string.Format("select uid from group_member where gid = {0}", gid);
//dynamic rest = fb.Get("167899503240064/members");
dynamic parameters = new ExpandoObject();
parameters.q = query;
dynamic result = fb.Get("/fql", parameters);
// JObject GroupListJson = JObject.Parse(result.ToString());
var r1 = (from i in (IEnumerable<dynamic>)result.data
select new
{
i.id
});

Permissions
To read the group_member table you need:
any valid access_token if the group is public (i.e. the group's privacy setting is OPEN)
user_groups permission for a user's non-public groups or to see the bookmark_order
or unread fields for a user's groups
friends_groups permission for a
user's friend's non-public groups
Previous to the query, you need to request the user_groups permission.
To get this working, please start from here: How to use user permissions with Facebook C# SDK

Related

facebook batch/fql friendlists a friend is member of

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.

FQL for getting facebook user ids does not return "paging" key in response

Hi i want to get list of my fabebook friend ids with paging of 100 users.
The problem is that if i set hte FQL to
NSString *fqlString = #"SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) LIMIT 300";
It returns me as expected the only first 300 users in the table with out any reference to next page.
Result: {
data = (
{
uid = 1519xxx;
},
{
uid = 9806xxx;
}
....
);
}
if i request friends with [FBRequest requestForMyFriends] it returns me all of my friends and additionaly a paging key with the url object for next page.
The question is how can i tell with FQL to give me lists of 100 users with paging to next 100 users.
The Graph API returns paging links; FQL does not. So you’d have to do that yourself, by making another query including an OFFSET parameter.

Get Friendlist using JSSDK after Page like

I've seen many fanpages getting my friendlist after I like their page, without any permission dialog screen, I've tried alot to do it but always got "exception token required".
So is it possible to get users friends list after they like our page??
Thanks
Note, I am using underscore.js (http://documentcloud.github.com/underscore/) with no conflict:
var UnderScore = _.noConflict();
This query gets friends for me(), which is currently logged in Facebook user. You can replace me() with a Facebook user id.
Code to get friends:
var friends = {handles:[],ids:[],names:[]};
var q = 'select username, uid, name from user where '+
'uid IN (SELECT uid2 FROM friend WHERE uid1 = me())';
var r=FB.Data.query(q);
r.wait(function(rows){
if (UnderScore.isArray(rows) && (rows.length>0)) {
UnderScore.each(rows,function(i){
if (i.username && !UnderScore.isNull(i.username)) {
friends.handles.push(i.username.toString().toLowerCase());
if (i.name && !UnderScore.isNull(i.name)) {
friends.names[i.username.toString().toLowerCase()] = i.name
}
}
if (i.uid && !UnderScore.isNull(i.uid)) {
friends.ids.push(i.uid.toString().toLowerCase());
if (i.name && !UnderScore.isNull(i.name)) {
friends.names[i.uid.toString().toLowerCase()] = i.name
}
}
});
}
}
After that code runs, which will be an asynchronous event, the variable friends will be populated with ids, names, and handles for Facebook friends.
No this is not possible. You need the current user id with sufficient permissions to get the user's friends' list, and Facebook won't share the user's id just by him liking your page.
I'm not sure how these pages you are talking about are doing it, maybe using the old deprecated FBML, but again...I don't think this is possible without user authorization.

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.

Facebook API : Data dump of Comment/Like Data

Here is my code:
string code = Request.QueryString["code"];
string appId = "x";
string appSecret = "x";
if (code == "" || code == null)
{
//request for authentication
Response.Redirect("https://graph.facebook.com/oauth/authorize?client_id=" + appId + "&redirect_uri=http://localhost:62543/&scope=email,read_stream");
}
else
{
var fb = new MyFB();
fb.ApplicationSecret = appSecret;
fb.ApplicationID = appId;
string accessToken = fb.GetAccessToken(code);
fb.AccessToken = accessToken;
var fbc = new FacebookClient(accessToken);
dynamic streams = fbc.Query("select post_id from stream where permalink = 'http://www.facebook.com/kevin.clough/posts/882439437244'");
Response.Write(streams.Count);
dynamic results = fbc.Query("select comments, likes from Post where id = " + streams.post_id);
foreach (dynamic comment in results.comments)
{
Response.Write(comment.from.name + ", " + comment.message + "<br/>");
}
}
Getting this error "A session cannot be used when querying the stream table with a viewer_id that is a different from the session owner."
How do I authorize this session to view my own data?
So the first problem I see is that the query is not valid. You have:
select post_id from stream
where permalink = 'http://www.facebook.com/kevin.clough/posts/882439437244'
Per the Facebook documentation here you can only query the stream table using the columns post_id, app_id, source_id, filter_key, and xid.
So you should change your first query to this (using post ID '19292868552_118464504835613' as an example):
select post_id from stream where post_id = '19292868552_118464504835613'
Alternatively, you could do the same thing with the graph using the post id:
dyanmic post1 = fbc.Get("19292868552_118464504835613");
Your second query is wrong mainly because you are querying a table that doesn't exist.
select comments, likes from Post where id = " + streams.post_id
There is no such FQL table 'Post'. I am not sure what the goal of this is, but if you want to get the likes and comments I think it would be easier to use the Graph API.
Comments:
dynamic comments = fbc.Get("19292868552_118464504835613/comments");
Likes:
dynamic likes = fbc.Get("19292868552_118464504835613/likes");
Here is Facebook's documentation on the Post Graph API: http://developers.facebook.com/docs/reference/api/post/
EDIT:
To determine the stream items of a user you will want to read their feed. You can do this using the Graph API also.
dynamic feed = fbc.Get("me/feed");
foreach (dynamic post in feed.data) {
var post_id = post.id;
}
This will get you the most recent posts of the user. From there you can loop through them to find the one you want to get more details.