I am trying to fetch facebook friend list of the user but it returning only count of the friends.Bellow is my code .Is there anything wrong in this code?
-(void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user
{
[FBRequestConnection startWithGraphPath:#"/me/friends"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
NSLog(#"me/friends result=%#",result);
NSLog(#"me/friends error = %#", error.description);
NSArray *friendList = [result objectForKey:#"data"];
//[m_allFriends addObjectsFromArray: friendList];
}];
}
When you registered your app to facebook. Facebook provide only three permission , these permission is by default approved
user_friends Provides access to a person's list of friends that also use your app. This permission is approved by default.
according to this you can get only those friend who use your app.
check this link
https://developers.facebook.com/docs/graph-api/reference/v2.3/user/friends
Related
i am using this code for getting Facebook friend list in iOS sdk 8.1.
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
NSArray* friends = [result objectForKey:#"data"];
NSLog(#"Found: %lu friends", (unsigned long)friends.count);
for (NSDictionary<FBGraphUser>* friend in friends) {
NSLog(#"I have a friend named %# with id %#", friend.name, friend.objectID);
}
}];
but it returns null value.
Since Graph API v2.0, the /{user_id}/friends endpoint does only return those friends who also gave your app the respective permission.
See
https://developers.facebook.com/docs/apps/changelog#v2_0
The /me/friends endpoint no longer includes the full list of a person's friends. Instead, it now returns the list of that person's friends who are also using your app.
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).
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) {
//...
}];
I am trying to retrieve a list of a user's Facebook friends by using the code
[FBRequestConnection startWithGraphPath:#"/me/friends"
parameters:nil HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id 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);
}
}];
But whenever I use that code it just returns Found: 0 friends. I'm putting it inside the Viewcontroller to execute after the user logs in through Facebook. I already requested user_friends permissions and I have a friend who is signed up on the app. If it makes any difference the app is also using Quickblox SDK so if there's any way to do it with that that'd be great!
use this code
FBRequest *friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler:^(FBRequestConnection *connection,NSDictionary *result ,NSError *error){
NSLog(#"Friend data :%#",result);
NSArray *friends = [result objectForKey:#"data"];
NSLog(#"friends :%#",friends);
for (NSDictionary<FBGraphUser>* friend in friends) {
NSLog(#"I have a friend named %# with id %#",friend.name,friend.id);
}
}];
Have a look at Facebook Graph Api v2.0+ - /me/friends returns empty, or only friends who also use my app
This is by design and has been discussed dozens of times here.
I am using Facebook graph api in my app. I want to get user's posted videos. When I login I get basic info. But when i query about posts i only get id in result.
My code is:
-(void)getPosts {
NSMutableDictionary *par = [[NSMutableDictionary alloc]init];
[par setObject:#"posts" forKey:#"fields"];
[FBRequestConnection startWithGraphPath:#"me"
parameters:par
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
)
{
//handle the result
if(!error)
{
NSLog(#"%#",result);
}
else
{
NSLog(#"%#",[error localizedDescription]);
}
}];
}
Please help if I am doing wrong or missing something. Thanks in advance
with the referance from facebook dev API
https://developers.facebook.com/docs/graph-api/reference/v2.0/user/videos
you got Logged in User Video using this method:
/* make the API call */
[FBRequestConnection startWithGraphPath:#"/me/videos"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
/* handle the result */
}];
it's Filed object is
You need to set first Permission of user_videos as par doc said:
A user access token with user_videos permission is required to see all videos that person is tagged in or has uploaded.
HERE IT IS SAMPLE CODE:
http://www.filedropper.com/fblogin
1) Here is a basic logic to get User's uploaded video...(shows all videos that were published to Facebook by user)
/* make the API call */
[FBRequestConnection startWithGraphPath:#"me/videos/uploaded"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
/* handle the result */
arrFbUserUploadVideos= [result objectForKey:#"data"]; //get all data in NSMutableArray
}];
Note: This will give the video Uploaded by the user..
2) and if you also want video list in which User tag (shows all videos use person is tagged in) in that case
/* make the API call */
[FBRequestConnection startWithGraphPath:#"me/videos"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
/* handle the result */
arrFbUserTagVideos= [result objectForKey:#"data"]; //get all data in NSMutableArray
}];
Note: This will give the video in which user is tag..
HERE IS A REFERENCE LINK: