I am trying to get Friendlist details using Facebook iOS SDK using the below query:
if (FBSession.activeSession.isOpen) {
[FBRequestConnection startWithGraphPath:#"me?fields=id,name,friendlists&fields=id,name,members&fields=pic,can_post,id,link,name,pic_crop,pic_large,pic_small,pic_square,profile_type,username,picture,list_type" completionHandler:^(FBRequestConnection *connection,id user, NSError *error) {
}];
I know the mistake is in using the '&' while constructing the query but I am not knowing how to nest the query (to get details like pic, can_post, etc).
Can someone help?
You should do this
me?fields=name,about,accounts.fields(about)
if you'd like to request 'user' (include name, about) and account connection (include 'about' field)
2nd connection you must user . (dot notation) instead of ?fields=
You should use + startForMyFriendsWithCompletionHandler:(FBRequestHandler)handler:
if (FBSession.activeSession.isOpen) {
[FBRequestConnection startForMyFriendsWithCompletionHandler:^(FBRequestConnection *connection,id user, NSError *error) {
}];
}
Note that it would get all the fields from your friends. If you want only a few ones, you can use startWithGraphPath:completion: with #"me/friends?fields=id,name,pic_square as graph path.
Related
Hi I am working in xcode 6.4.
I am trying to create an application which integrate with Facebook.I want to fetch the event details of the user. That is, I want event_name, place, time, number of friends going and their details. I found many answers for this problem here and I tried them. But I couldn't build the app with that much of information. Please give me a detailed solution for the same.
[FBRequestConnection startWithGraphPath:#"me/events"
parameters:#{#"fields":cover,name,start_time,end_time"} HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
if (!error)
{
NSLog(#"event_name%#",[result objectForKey:#"name"]);
NSLog(#"start_time%#",[result objectForKey:#"start_time"]);
NSLog(#"end_time%#",[result objectForKey:#"end_time"]);}
else
{
NSLog(#"%#", [errolocalizedDescription]);
}
}];
I'm trying to fetch Facebook posts for a public page using the Facebook SDK for iOS. I can't seem to figure out how to get and then use the access token I need to make this request. Let's say it's the New York Times page. This shouldn't require any permissions, so I should be able to use the App Access Token...but again, I can't figure out how to get & use that.
The code I am using looks like this:
[FBRequestConnection startWithGraphPath:#"/nytimes/posts" completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
NSLog(#"DATA: %#", [result data]);
NSLog(#"ERROR: %#", error);
}];
I keep receiving an error saying that an access token is required.
Please help!
It means it asking you a permission to access the public post in view did load method put one line code like (readPermissions = #[#"public_profile", #"email",#"user_friends",#"user_likes",#"user_groups"];)
, for more details see this https://developers.facebook.com/docs/facebook-login/permissions/v2.2.
I'm trying to get user's list of friends by authanticate user and successfully when I use this code:
self.loginView.readPermissions = #[#"public_profile", #"user_fridends", #"email"];
[FBRequestConnection startWithGraphPath:#"/me/taggable_friends"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
/* handle the result */
NSLog(#"%#", result);
}];
But I cannot get list of friends when I trying to get list of friends by another account
https://developers.facebook.com/docs/graph-api/reference/v2.1/user/taggable_friends
Use of this edge must be reviewed by Facebook before it can be called on behalf of people who use your app.
Without approval, it will only work for users with a role in the App (Admin/Dev/Tester). The proper way to get the friends is /me/friends, and it will only return those who authorized your App too.
Also, it is "user_friends", not "user_fridends".
I have been trying to create an event on the behalf of my page using the Facebook Graph API for iOS.
However, I always fail with the error code 403. I have tried to create an event on behalf of me - and surprisingly that works. The permissions are set appropriately as stated here.
My code goes like:
NSMutableDictionary *postParams = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
#"Test",#"name",
#"2012-11-11", #"start_time", nil];
[FBRequestConnection
startWithGraphPath:#"12345/events"
parameters:postParams
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (error) {
NSLog(#"Error: %#", result);
} else {
NSLog(#"Success: %#", result);
}
}];
How I said, if I set the ID/events to my user ID instead of my Page's ID, it works. Could I have set up something badly on my page? Do I need admin rights for that page?
I found something about access tokens to "Perform the following operations as a Page" here. Do I need that? If so, how do I do it?
Thanks to everyone in advance!
To authenticate as a Page (and from there, edit the events) see this document: https://developers.facebook.com/docs/authentication/pages/
In short, authenticate as user who is an an admin of the Page. Then:
https://graph.facebook.com/me/accounts?access_token=xxx
in order to retrieve the access token for the Page (and indeed for any other Pages the user administers).
Then use that access token to administer the events for the Page.
I'm using the Facebook SDK for iPhone. I need to be able to retrieve the authenticated users details AND profile picture in one request.
In the beta's of the SDK I used to be able to do this using the following code below, but it is now only returning the user id and the picture url.
[FBRequestConnection startWithGraphPath:#"me" parameters:[NSDictionary dictionaryWithObject:#"picture" forKey:#"fields"] HTTPMethod:#"GET" completionHandler:^(FBRequestConnection *connection, id result, NSError *error)...
Is there a way to do this in one request? Many thanks for any advice.
[EDIT] I should also probably mention that I require the URL string to the image directly as I am not using Facebook's new FBProfilePictureView class.
Brain fart! I should have included all the properties I wanted returned in the parameters dictionary. I was under the impression from Facebook's doc that you only had to include the picture property if you wanted it returned WITH the user information. The correct request is as below:
[FBRequestConnection startWithGraphPath:#"me"
parameters:[NSDictionary dictionaryWithObject:#"picture,id,birthday,email,first_name,last_name,gender,username" forKey:#"fields"]
HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
}];
Here is an updated solution.
var basicUserData = ["fields": "picture,id,birthday,email,first_name,last_name,gender"]
FBRequestConnection.startWithGraphPath("/me",
parameters: basicUserData,
HTTPMethod: "GET") {
(connection:FBRequestConnection!, result, error) -> Void in
if error != nil {
print(error!)
} else {
print(result!)
}
}
The Parse team recommended getting FB profile picture by accessing the https://graph.facebook.com/(facebookId)/picture?type=large Make sure to replace with the user's Facebook Id. Here is the discussion
Notes:
username field is deprecated after FacebookSDK v2
"/me" is the correct endpoint not "me"
This gist shows many other interactions with the Facebook Graph