I want to extract birthdays of friends who are using my app; I'm unable to access it.
FBRequest *friendRequest = [FBRequest requestForGraphPath:#"me/friends?fields=name,birthday"];
[friendRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
NSArray *data = [result objectForKey:#"data"];
for (FBGraphObject<FBGraphUser> *friend in data)
{
NSLog(#"%#:%#:%#", [friend id], [friend name], [friend birthday]);
}
}
Permissions on didLoad:
self.loginButton.readPermissions = #[#"public_profile", #"email", #"user_friends", #"friends_birthday"];
facebook is remove some of the accessibility of friend in Facebook V 2.1. friend birthday is also removed. so you can't get the date of friend birthday.
List of All friends_* permissions has been removed. They include:
friends_about_me
friends_actions.books
friends_actions.fitness
friends_actions.music
friends_actions.news
friends_actions.video
friends_actions:APP_NAMESPACE
friends_activities
friends_birthday
friends_checkins
friends_education_history
friends_events
friends_games_activity
friends_groups
friends_hometown
friends_interests
friends_likes
friends_location
friends_notes
friends_online_presence
friends_photos
friends_questions
friends_relationships
friends_relationship_details
friends_religion_politics
friends_status
friends_subscriptions
friends_videos
friends_website
friends_work_history
Facebook reference link
Facebook is restrict the some functionalities of friends list and details in Facebook V 2.1. You can fetch only:
id
name
picture only
Documentation reference.
Related
I have a problem i implement Facebook SDK in my view controller and want to get list of friends and email using Facebook. I wrote this:
FBLoginView *loginView = [[FBLoginView alloc] initWithReadPermissions:#[#"public_profile", #"email", #"user_friends"]];
loginView.delegate = self;
and then use the protocol method of FBLoginViewDelegate:
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
user:(id<FBGraphUser>)user
{
self.profilePictureView.profileID = user.id;
self.nameLabel.text = user.name;
NSLog(#"%#", user);
NSLog(#"%#", [user objectForKey:#"email"]);
}
In console i got this:
2014-12-04 14:56:48.746 FBLoginUIControlSample[2941:613]
"first_name" = Pavel;
gender = male;
id = 1379600000000000;
"last_name" = name;
link = "https://www.facebook.com/app_scoped_user_id/1379600000000000/";
locale = "ru_RU";
name = "Pavel name";
timezone = 2;
"updated_time" = "2014-12-03T11:47:13+0000";
verified = 1;
2014-12-04 14:56:48.748 FBLoginUIControlSample[2941:613] (null)
sorry , but you can't
Read Facebook Permissions
you only can get the email when the user login , but you can't get user's friends email.
i am not really sure but maybe you can use "friendsusername"#facebook.com ("facebook email").
i found this, https://www.facebook.com/help/224049364288051
the person has to active #facebook option.
For friends with Facebook SDK 3.0 you can do this
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
NSArray* friends = [result objectForKey:#"data"];
NSLog(#"Found: %i friends", friends.count);
for (NSDictionary<FBGraphUser>* friend in friends) {
NSLog(#"I have a friend named %# with id %#", friend.name, friend.id);
}
}];
You can not access to any users email, excepts of yours.
Because FBGraphUser doesn't have an email #property, we can't access the information like with the name (dot-syntax), however the NSDictionary still has the email kv-pair and we can access it like we would do with a normal NSDictionary.
With this method you can access to your email.
if (FBSession.activeSession.isOpen) {
[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (!error) {
self.nameLabel.text = user.name;
self.emailLabel.text = [user objectForKey:#"email"];
}
}];
}
hope this will help you
you can get your friend list by using below code in your viewDidLoad
[FBRequestConnection startWithGraphPath:#"me/taggable_friends"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
}];
and some info
EDIT
the above answer only mention for friendlist not email(as its already quite clear by above answers) , now what you want friendlist
A friend list(Friend List V 2.2) - an object which refers to a grouping of friends created by someone or generated automatically for someone (such as the "Close Friends" or "Acquaintances" lists)
from v2.0 you'll only be able to get all friends via the /me/taggable_friends (see it by result)
I know it have been asked a lot here, but I can't find a proper answer for that.
I am using Facebook SDK v3.18
I simply want to get user friends list and their pictures .
I've tried so far this:
Login:
FBLoginView *loginView =
[[FBLoginView alloc] initWithReadPermissions:
#[#"public_profile", #"email", #"user_friends"]];
// Align the button in the center horizontally
loginView.frame = CGRectOffset(loginView.frame, (self.view.center.x - (loginView.frame.size.width / 2)), (self.view.center.y - (loginView.frame.size.height / 2)));
[self.view addSubview:loginView];
Get user's friends list and their pictures:
[FBRequestConnection startWithGraphPath:#"/me/friends?fields=name,picture"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
/* handle the result */
}];
But the answer is:
{
data = (
);
summary = {
"total_count" = 1216;
};
}
And non for my friends name or pictures are shown :/
Please put some light for me on this.
Thanks in advance!
From the Facebook SDK page, it looks like /me/friends will only return your friends that have logged in and given permission to the same app (i.e. you and your friends need to have permitted your app to use facebook via login).
Did you tried below ?
FBRequest* friendsRequest = [FBRequest requestWithGraphPath:#"me/friends?fields=name" parameters:nil HTTPMethod:#"GET"];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
NSArray* friends = [result objectForKey:#"data"];
NSLog(#"Found: %i friends", friends.count);
for (NSDictionary<FBGraphUser>* friend in friends) {
NSLog(#"I have a friend named %# with id %#", friend.name, friend.id);
}
NSArray *friendIDs = [friends collect:^id(NSDictionary<FBGraphUser>* friend) {
return friend.id;
}];
}];
Edit:
Please check this post.
Facebook Graph Api v2.0+ - /me/friends returns empty, or only friends who also use my app
I'm developing a social networking app. I've integrated Facebook SDK 3.14 in my iOS App. Now, I want to get the list of all my Facebook friends so I can invite those friends who are not using the app and send friend requests to those friends who have already installed the app.
I can get the list of friends who already use my apps using "/me/friends".
[FBRequestConnection startWithGraphPath:#"/me/friends"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSLog(#"All == %#", result);
}];
It gives friends' Facebook ids (ex. id = 654330727444458) in response so that I can send friend requests to them.
To get the list of all Facebook friends who have not downloaded the app and if I want to invite those, I need to get all friends using "me/taggable_friends" (Please correct me if I'm wrong).
[FBRequestConnection startWithGraphPath:#"/me/taggable_friends"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSlog("%#", result);
}];
In the taggable_friends response I'm getting friend's id as id = "AaLYBzZzHdzCmlytqyMAjO0OLDZIOs74Urn93ikeRmmTB3vX_Xl81OYUt4XnoWG0BDLuX67umVkheVdDjzyvm0fcqMqu84GgM9JnNHc-1B63eg" which is friend's token id and it's not unique. I couldn't use it instead, have to use Facebook Id of friend to invite them. Unfortunately, I couldn't get it in the taggable friend response.
This is only possible on the Facebook API v1 which stops working next April or so. Even now only existing Facebook apps will allow you to use V1 so if you don't have an old enough app you are not able to do this. In V2 you can only get friends who have also signed in to the same app but the user id's are unique to the application to prevent exactly this. I guess Facebook reasons that by doing this is stops people spamming their friends via apps so much :/
As #joelrb says you can create a canvas app for a game and use invitable_friends but FB will vet your "game" so you can't really cheat.
See https://developers.facebook.com/docs/apps/changelog/ for more info.
TLDR; post to wall is all you can do. Tough. Sorry.
Use the installed field of a user. Like so:
NSMutableArray *notYetUsers = [NSMutableArray array];
FBRequest *fbRequest = [FBRequest requestForGraphPath:#"me/friends?fields=installed"];
[fbRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSAssert(!error, error.localizedDescription);
NSArray *friends = [(NSDictionary *)result objectForKey:#"data"];
for (NSDictionary<FBGraphUser> *user in friends) {
if ([user[#"installed"] isEqual:#(NO)])
[notYetUsers addObject:user];
}
}];
notYetUsers would contain all friends who have not installed the app yet.
- (void)getFBFriendsWithCompletion:(void (^)(NSError *, id))callback
{
NSString *query = #"select uid, name, is_app_user "
#"from user "
#"where uid in (select uid2 from friend where uid1=me() )";
NSDictionary *queryParam =
[NSDictionary dictionaryWithObjectsAndKeys:query, #"q", nil];
// Make the API request that uses FQL
[FBRequestConnection startWithGraphPath:#"/fql"
parameters:queryParam
HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (callback)
callback(error, result);
}];
}
- (void)foo
{
[self getFBFriendsWithCompletion:^(NSError *error, id result) {
if (!error)
{
NSMutableArray *friendsUsingApp = [NSMutableArray array];
NSMutableArray *friendsNotUsingApp = [NSMutableArray array];
for (NSDictionary *data in result[#"data"]) {
if ([data[#"is_app_user"] boolValue] == NO) {
[friendsNotUsingApp addObject:data];
} else {
[friendsUsingApp addObject:data];
}
}
// Do something with friendsUsingApp and friendsNotUsingApp
}
}];
}
taggable_friends refers to a list of friends that can be tagged or mentioned in stories published to Facebook. The result you got is just a tagging token which can only be used in order to tag a friend, and for no other purpose.
Although this refers to a game app, it's easier I think if you use the invitable_friends API. But it requires a Facebook Canvas app implementation. You may just provide a notice in your Canvas for users to just use the mobile app instead, etc.
This is the tutorial that uses invitable_friends API: https://developers.facebook.com/docs/games/mobile/ios-tutorial/
And, the invitable_friends API details:
https://developers.facebook.com/docs/games/invitable-friends/v2.0
You can try this to get the IDs of Friends app users:
NSMutableArray *appFriendUsers = [[NSMutableArray alloc] init];
[[FBRequest requestForGraphPath:#"me/friends?fields=installed"]
startWithCompletionHandler:
^(FBRequestConnection *connection,
NSDictionary *result,
NSError *error) {
//if result, no errors
if (!error && result)
{
//result dictionary in key "data"
NSArray *allFriendsList = [result objectForKey:#"data"];
if ([allFriendsList count] > 0)
{
// Loop
for (NSDictionary *aFriendData in allFriendsList) {
// Friend installed app?
if ([aFriendData objectForKey:#"installed"]) {
[appFriendUsers addObject: [aFriendData objectForKey:#"id"]];
break;
}
}
}
}
}];
Is there any way that i can get friend list of any of my friends by using their user id or username??
I used FBfriendPickerDelegate to get my friend list but how can i get others friendlists by their id?
UPDATE THE ANSWER
I found a solution for it
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
NSArray* friends = [result objectForKey:#"data"];
NSLog(#"Found: %i friends", friends.count);
NSString * friendListString = #"" ;
for (NSDictionary<FBGraphUser>* friend in friends) {
NSLog (#"Friend Name %#,Friend ID %#",friend.name,friend.id);
}
Only with a valid access_token and permissions otherwise the ability to abuse this and spam people would be too great. A user must explicitly grant your app access to their friends/friendlists for you to access them
https://developers.facebook.com/docs/facebook-login/permissions/v2.0#reference-friends
Since Apr 30th's Facebook API v2.0, it's no longer possible to get any of your friends information (all user_* permission were removed).
I am using the FBDialogs to open Facebook Messenger (if user has it installed on the device) to send a personal message. However I cannot already preselect friends in my app (messenger always gives me a list and prompts me to select there).
I am using presentMessageDialogWithParams:clientState:handler: which receives FBLinkShareParams object.
FBLinkShareParams friends array
An array of NSStrings or FBGraphUsers to tag in the post. If using NSStrings, the values must represent the IDs of the users to tag.
But when I send FBGraphUsers they are not preselected in messenger app. Should they? Or is this just a "tag a friend" feature?
My code:
NSMutableArray *inviteFriends = [[NSMutableArray alloc] init];
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
NSArray* friends = [result objectForKey:#"data"];
NSLog(#"Found: %i friends", friends.count);
for (NSDictionary<FBGraphUser>* friend in friends) {
if ([friend.name isEqualToString:#"XXX"]) {
NSLog(#"I have a friend named %# with id %#", friend.name, friend.id);
[inviteFriends addObject:friend];
}
}
FBLinkShareParams *params = [[FBLinkShareParams alloc] init];
params.link = [NSURL URLWithString:#"https://developers.facebook.com/docs/ios/share/"];
params.name = #"Message Dialog Tutorial";
params.caption = #"Build great social apps that engage your friends.";
params.picture = [NSURL URLWithString:#"http://i.imgur.com/g3Qc1HN.png"];
params.description = #"Send links from your app using the iOS SDK.";
params.friends = inviteFriends;
// If the Facebook app is installed and we can present the share dialog
if ([FBDialogs canPresentMessageDialogWithParams:params]) {
[FBDialogs presentMessageDialogWithParams:params clientState:nil handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
//
}];
}
}];
The "friends" and "place" parameters are ignored by Messenger since those are specific for tagging, and Messenger doesn't support tagging.
You cannot specify users to preselect using the message dialog.
We will update the docs to reflect this in the future.