Facebook friends list in IOS is always empty - ios

I am trying fetch my Friends who are using my application from facebook and but in the response i am getting empty list list. Please guide me what i am doing wrong. I am using the following code
[[FBRequest requestForMe] startWithCompletionHandler: ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (error) {
//error
NSLog(#"%#",error);
}else{
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,NSDictionary* result,NSError *error) {
NSArray* friends = [result objectForKey:#"data"];
NSLog(#"%#",result);
for (NSDictionary<FBGraphUser>* friend in friends)
{
NSLog(#"%# %d",friend.username,[friend.id intValue]);
}
}];
}
}];
Thanks

Possible reasons:
1) You don't have the rights to get connections of this account (wrong apikey/passkey or rights not properly set)
2) Check what is stored in "result" variable and the answer status: it may guide you in some way.
3) Finally, try to get some simpler informations (like your own username) to be sure you have access to these informations.

In the new version of Facebook's API you will get ONLY friends that installed the app (i.e. is_app_user is 1).
You can't get friends who haven't logged in with your app anymore.
Instead, you can get taggable_friends. This will return a list with all of your friends, but here "id" field will be different, not the real facebook id. Its only for tagging, i.e. for passing to field "tags" like:
NSDictionary *params = #{#"message":self.invitationText.text,
#"tags":ids,
#"caption":#"...",
#"name":#"...",
#"place":#"123456789",
#"link":APP_STORE_URL};
[FBRequestConnection startWithGraphPath:#"/me/feed"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
//...
}];

Related

Facebook SDk3 how can i get the Facebook all friend list in my tableview and also i want to write some text on the particular friend

how can i get the Facebook all friend list in my iOS Application tableview and also i want to write some text on the particular friend
I'm using Facebook latest sdk
code :
[FBRequestConnection startWithGraphPath:#"/me/friends"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection, id<FBGraphUser> result, NSError *error) {
/* handle the result */
NSLog(#"%#", result);
}];
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);
}
}];
Hope this helps..

How to list ALL friends using Graph API 3.x version?

I try to login user to my app with the following permissions:
NSArray* permissions = [[NSArray alloc] initWithObjects:#"email", #"read_friendlists", #"user_friends", nil];
After login I don't get "read_friendlists" permission from
[FBRequestConnection startWithGraphPath:#"/me/permissions"....];
request.
I think this is the reason, why I can't get the full friend list.
I tried to get the list with the following methods:
[FBRequestConnection startWithGraphPath:#"me/friends"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
NSLog(#"FriendList: %#", result);
/* handle the result */
}];
AND
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>* friendIns in friends) {
NSLog(#"I have a friend named %# with id %#", friendIns.name, friendIns.id);
}
}];
These methods give me the friends, who also use my app, and not the whole friend list.
What's wrong with my method(s)?
How to get the full friend list from user?
read_friendlists is not for getting friends, but only for getting the lists you created (without any friends in it). It also needs approval from Facebook before you can use it, but it´s definitely not what you want.
user_friends is for getting access to the friends who authorized your App too, with /me/friends. That would be the appropriate way.
There is no way to get ALL friends anymore, unless you want to tag friends (taggable_friends) or invite friends to a game on Facebook Canvas (invitable_friends).

Get user friends with Facebook SDK 3.1

I'm trying to get the user's friend list with iOS Facebook SDK 3.1 but I'm getting an empty list as a result. This is what I'm doing:
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
NSArray* friends = [result objectForKey:#"data"];
for (NSDictionary<FBGraphUser>* friend in friends) {
NSLog(#"NAME %#", friend.name);
}
}];
I'm getting this:
{
data = (
); }
This app has also Facebook Login and it works OK. What am I missing?
Thanks in advance!

Facebook iOS sdk to take user id

a question about Facebook sdk for iOS.
If I have an active session how can I get only the user ID?
Is there a simple way to obtain this id without use this example code?
if (FBSession.activeSession.isOpen) {
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *aUser, NSError *error) {
if (!error) {
// I can take the user id..
}
}];
}
+ (NSString *)activeUserId {
return [FBSDKAccessToken currentAccessToken].userID;
}
if you are already logged in on facebook.
This is best way to take user id, instead of directly access using dot.
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *aUser, NSError *error) {
if (!error) {
NSLog(#"User id %#",[aUser objectForKey:#"id"]);
}
}];
[FBRequestConnection startWithGraphPath:#"/me"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
NSDictionary *result,
NSError *error
) {
/* handle the result */
_fbId = [result objectForKey:#"id"];
}];

Facebook SDK FBRequest requestForMe Incompatible pointer types

I am running into issues trying upgrade my Facebook SDK to the latest production release (FacebookSDK-3.0.8.pkg - Facebook SDK 3.0 for iOS (update 1) [August 21, 2012]).
I am following along with tutorial on this page.
I have ran into several issues trying to get the code to work, it's not as easy as it proclaims to be in the tutorial. I can get my session open, but can not get the request to work.
- (IBAction)facebookTapped:(id)sender {
[FBSession openActiveSessionWithPermissions:nil allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if(error) {
NSLog(#"Error opening session: %#", error);
return;
}
if(session.isOpen) {
NSLog(#"session is open");
FBRequest *me = [FBRequest requestForGraphPath:#"me"];
[me startWithCompletionHandler:^(FBRequestConnection *connection,
NSDictionary<FBGraphUser> *my,
NSError *error) {
NSLog(#"My name: %#", my.first_name);
}];
}
}];
}
My console displays that the session is open if I remove the call to FBRequest requestforGraphpath. If I leave it in, I receive the error "Incompatible block pointer types initializing 'void(^)(struct FBRequestConection , struct NSDictionary, struct NSError*)', expected 'FBRequestHandler'
Now what has me stumped is that this is the exact code shown in the tutorial, excpet that I changed out [FBRequest requestForMe] trying different approaches. None worked.
Can anyone shed some light on this for me?
Thank you.
I was able to solve this issue by changing their original block in the tutorial of:
if (session.isOpen) {
FBRequest *me = [FBRequest requestForMe];
[me startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary<FBGraphUser> *my,
NSError *error) {
self.label.text = my.first_name;
}];
}
to
if(session.isOpen) {
FBRequest *me = [FBRequest requestForMe];
[me startWithCompletionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
NSDictionary<FBGraphUser> *my = (NSDictionary<FBGraphUser> *) result;
NSLog(#"My dictionary: %#", my.first_name);
}];
}

Resources