Is there already a way with the facebook ios API to get a list of friends who have your app installed? I basically require something similar to "Words with Friends" where they can determine which of your FB friends are playing the game. I have one solution which requires some extra database use but was hoping maybe the FB api had something built in for this kind of query.
Scroll down and tap Settings, then tap Apps and Websites. Tap Logged in with Facebook. Tap the app that you want to adjust who can see your activity, then tap . Choose who you want to see that you use the app: Public, Friends or Only me.
Tap in the top right of Facebook. Scroll down and tap Settings. Tap Apps and Websites.
Finding and playing games on FacebookTap in the top right of Facebook. Tap Games. Tap Play at the top of the screen. Scroll down to find a game.
You won't find information or content that you deleted because we delete that content from our servers. Keep in mind: The categories of data we receive, collect, and save may change over time. Learn more about your Facebook data in our Privacy Policy.
Create a FBFriendPickerDelegate
delegate class and override this function:
-(BOOL)friendPickerViewController:(FBFriendPickerViewController *)friendPicker shouldIncludeUser:(id<FBGraphUser>)user{
BOOL installed = [user objectForKey:@"installed"] != nil;
return installed;
}
For users that do not have your app installed, installed
field will be nil
, but you have to request it when you load data:
self.friendsController = [[FBFriendPickerViewController alloc] initWithNibName:nil bundle:nil];
//...
NSSet *fields = [NSSet setWithObjects:@"installed", nil];
self.friendPickerController.fieldsForRequest = fields;
//...
[self.friendsController loadData];
I think fql is a little complex for me,so I use this function in FBRequest to call the Graph API to solve this problem in Facebook SDK 3.5
+ (FBRequest *)requestWithGraphPath:(NSString*)graphPath parameters:(NSDictionary*)parameters HTTPMethod:(NSString*)HTTPMethod;
And the code is:
FBRequest *request = [FBRequest requestWithGraphPath:@"me/friends"
parameters:@{@"fields":@"name,installed,first_name"}
HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBRequestConnection *connection,
id result,
NSError *error){
}];
You can put all your interesting fields in the parameters dictionary. And according to the SDK Reference,object containing type (this is always "user"), id (the ID of the user), and optional installed field (always true if returned); The installed field is only returned if the user has installed the application, otherwise it is not part of the returned object
I've used this code in the past to get app using friends from a user.
facebook
is the Facebook
class that comes with FB Connect.
NSString *fql = [NSString stringWithFormat:@"SELECT name,uid, pic_small FROM user WHERE is_app_user = 1 AND uid IN (SELECT uid2 FROM friend WHERE uid1 = %@) order by concat(first_name,last_name) asc",userId,userId]];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:fql ,@"query", [facebook accessToken], @"access_token", nil];
[facebook requestWithMethodName:@"fql.query" andParams:params andHttpMethod:@"GET" andDelegate:self];
The easiest solution is using the
- (BOOL)friendPickerViewController: shouldIncludeUser:
method implemented by the FBFriendPickerDelegate protocol in the latest 3.5.1 Facebook SDK (June 2013), asking the delegate whether to include a friend in the list, based on the "installed" field when fetching me/friends.
The installed field is present (true) if the friend is also a user of the calling application.
You can use like this:
- (BOOL)friendPickerViewController:(FBFriendPickerViewController *)friendPicker
shouldIncludeUser:(id <FBGraphUser>)user {
return [[user objectForKey:@"installed"] boolValue];
}
IMPORTANT! You have to include the followings to include the field in the request and to inform friendPicker about its delegate:
self.fieldsForRequest = [NSSet setWithObject:@"installed"];
self.delegate = self;
You can verify with the Graph Api Explorer that only friends with the apps installed display by using the Graph API Explorer and entering the query
me/friends?fields=installed
and you can get back a list of your friends like this, where one of the user has installed your application (true):
...
{
"id": "100002656xxxxxx"
},
{
"installed": true,
"id": "100004366xxxxxx"
},
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With