Getting the user’s Facebook list of friends - ios

After being able to create a small iOS app that logs in to Facebook. I would like this app to get the user’s list of friends.
Though I browsed the internet for a while and tried various approach I did not succeed to get what I wanted.
In the viewDidLoad method I use this code to start with:
loginView = [[FBLoginView alloc] initWithReadPermissions:#[#"user_friends"]];
And then I implement the loginViewFetchedUserInfo: user: method this way:
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
user:(id<FBGraphUser>)user
{
[FBRequestConnection startWithGraphPath:#"/me/friends"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
NSLog(#“Result: %#",result);
}];
}
When I execute the app I get this result:
Result: {
data = (
);
summary = {
"total_count" = 267;
}; }
But what I really want is a list of the friends with their names …etc…
All the things I tried for that didn’t work. Though I suppose the solution must be simple.
I also used code like this in the method above ….. but with no luck:
NSArray* friends = [result objectForKey:#"data"];
One more point, here https://developers.facebook.com/docs/graph-api/reference/v2.1/user/friends one can read:
This will only return any friends who have used (via Facebook Login)
the app making the request.
But the result I get (267) does not match this statement. It (267) is the number of friends the user has on Facebook, which is in fact what I am interested in.
I hope someone has something to say to put me on the right track and make things clearer.

Since Facebook's 2.x SDK upgrade they have tightened up access to information in the "Open Graph API."
Under Permissions That Do Not Require Review
App friends. This optional permission grants your app the ability to read a list of friends who also use your app.
You get automatic access to any friends that already use your app (per its Facebook ID.)
You will have to request Extended Permissions if you want to access the list of all a user's friends. That means going through Facebook's App Review process which can be quite challenging (and annoying.)
Frankly, I am not even sure that it is possible to use the new Open Graph API to get the user's entire friend list.

Related

Parameter for like count with facebook api V2.3

I am using this line of code for getting count of likes on facebook post
NSString *postId = #"1234567890_1234567890";
NSMutableDictionary* photosParams = [NSMutableDictionary dictionaryWithObjectsAndKeys:postId,#"ObjectId",nil];
NSString * str = (NSString *) [[[FBSDKGraphRequest alloc] initWithGraphPath:#"/{object-id}/likes"
parameters:photosParams
HTTPMethod:#"GET"]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if ([error.userInfo[FBSDKGraphRequestErrorGraphErrorCode] isEqual:#200]) {
NSLog(#"%#",[error localizedDescription]);
}
}];
but I am getting error of unsupported url, any one have Idea what parameter I use to get result. I am using updated version of facebook api
As
https://developers.facebook.com/docs/graph-api/reference/v2.3/object/likes
states, you need
The same permissions required to view the parent object are required to view likes on that object.
That means that the permission setting for Posts (https://developers.facebook.com/docs/graph-api/reference/v2.3/post) apply:
For page posts, public posts by the page are retrievable with any valid access token. Posts by people on the page, posts by people which mention the page, or targeted page posts (by language or geography, for example) may require a user or page token.
A user access token with read_stream or user_posts permission for any other posts
Are you sure you're adding an Access Token to your request?
You can request multiple posts at once like this:
/?ids={object_id1},{object_id2}&fields=id,created_time,likes.summary(true).limit(0)

Facebook friends Location info in iPhone app

Any one having a idea how to get Facebook friends location details from Facebook profile.
I am getting these details (id,name,gender,email, picture) using this graph API.
I also need location information.
Thanks!
To get friends location for 1.0 graph api,you can use following code.
if (FBSession.activeSession.isOpen) {
[FBRequestConnection startWithGraphPath:#"me/friends?fields=name,location,installed,picture"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
NSDictionary<FBOpenGraphObject> *my,
NSError *error
) {
NSDictionary *resultDictionary = (NSDictionary *)my;
if ([resultDictionary valueForKey:#"data"]) {
NSString * latitude = [NSString stringWithFormat:#"%#",[[my2 valueForKey:#"location"] objectForKey:#"latitude"]];
NSString *longitude=[NSString stringWithFormat:#"%#",[[my2 valueForKey:#"location"] objectForKey:#"longitude"]];
}
}];
}
Important Note me/friends will only return you those friends who have authorized your app since graph api 2.0 as mentioned here in facebook docs And all friends info are removed as mentioned except basic info like name , id , picture as mentioned here
In v1.0, it was possible to ask for permissions that would allow an
app to see a limited amount of friend data, such as a person's
friend's likes, their birthdays, and so on.
In v2.0, those permissions have all been removed. It's no longer
possible for an app to see data from a person's friends unless those
friends have also logged into the app and granted permission for the
app to see it that data

Facebook requestForMyFriends returns no friends data [duplicate]

This question already has answers here:
Facebook Graph API v2.0+ - /me/friends returns empty, or only friends who also use my application
(8 answers)
Closed 8 years ago.
I used the FBRequest to request the friend list of user.
FBRequest *requestFriendList = [FBRequest requestForMyFriends];
[requestFriendList startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error){
if (!error)
{
NSArray *fbFriends = [result objectForKey:#"data"];
//...
}
}];
However, the returned result of the request didn't contain any data. I printed out results, it contains the friend count, but no data inside.
Printing description of result:
{
data = (
);
summary = {
"total_count" = 585;
};
}
If the request failed or the app doesn't have permissions, should it return an error or the "total_count" also is not shown?
So is there anything I did wrong? Anyone can help me fix this problem?
Thanks!!
Graph API 2.0 changed the behaviour of the /friends endpoint.
It now returns the list of friends who have authorized your Facebook app, as opposed to the complete list of friends. It's also a new permission - user_friends.
From the Facebook Platform Changelog:
Friend list is no longer part of the default permission set and has
its own permission: Asking for access to a person's friend list is now
a separate permission that your app must request. The new permission
is called user_friends.
Friend list now only returns friends who also
use your app: The list of friends returned via the /me/friends
endpoint is now limited to the list of friends that have authorized
your app.

Share facebook without being able to edit text

I'm creating an game where I have a share button. In this share button I would like to share text and a link. It is important that the user can't edit the text since they would be able to change the score. What is the best solution for this? I've searched, but in most guides, you're able to change the text as a user.
What's the solution?
The short answer is that you're not supposed to post something on a user's behalf without giving them the option of editing the comment/status. You can do it with an API call (rather than a share sheet), but this should only be used to post content that the user entered elsewhere in the app.
// NOTE: pre-filling fields associated with Facebook posts,
// unless the user manually generated the content earlier in the workflow of your app,
// can be against the Platform policies: https://developers.facebook.com/policy
[FBRequestConnection startForPostStatusUpdate:#"User-generated status update."
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
// Status update posted successfully to Facebook
NSLog(#"result: %#", result);
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(#"%#", error.description);
}
}];
This is from Facebook's "Sharing in iOS" documentation
Another option (though possibly also against the rules) is to create an image from the text and let the user share the image. Before doing this, however, put yourself in the user's shoes - do you really need to post something like that?

Can FBRequestConnection startForCustomAudienceThirdPartyID be used on its own?

I want to get the app user ID for Facebook, as described here:
https://developers.facebook.com/docs/ads-for-apps/custom-audiences-for-mobile-apps/
The code snippet they give is:
[FBRequestConnection startForCustomAudienceThirdPartyID:nil
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSString *id = error ? nil : [result objectForKey:#"custom_audience_third_party_id"];
// Stash off this id, send it to your server, etc. Use later to construct
// a custom audience. A result of 'nil' means that either the user can't be
// identified, or they've limited ad tracking via iOS 6.
}
];
This always returns error 400 for me. Answers like this suggest that it needs to be used as part of a larger piece of code but there's no mention of this on the Facebook page.
Can I just use the snippet above, or do I need to implement something around it?
I got this from the FB developer page:
Discussion:
This method will thrown an exception if either <[FBSettings defaultAppID]> or <[FBSettings clientToken]> are nil. The appID won't be nil when the pList includes the appID, or if it's explicitly set. The clientToken needs to be set via <[FBSettings setClientToken:]>.
.....
Please check the conditions above first. Ass per documentation
startForCustomAudienceThirdPartyID: -> should actually point to the current FBSession
Right after the session is created do this: [FBSession setActiveSession:session];
Answered here: Facebook iOS SDK 3.1: "Error: HTTP status code: 400"

Resources