Facebook Profile Picture Large - ios

I am having trouble trying to request the large version of the users profile picture on Facebook.. in my graph path I'm doing:
NSString *requestPath = #"me/?fields=first_name,last_name,gender,email,birthday,verified,picture";
The picture field in there only gives me the small version of the profile picture, but i need the large and the normal version.. i already tried changing picture to picture_large, pic_large, image_large but none of this works..
Please, i already read the documentations, so don't bother answering if you plan on telling me to read it again.. I'm asking this here because i already searched everywhere and couldn't find a solution.
Thanks,
Newton

The short answer you are looking for is picture.type(large)
I was looking for the same thing and found the answer using Facebook Graph API explorer found here.
Now if I use the following code:
[FBRequestConnection startWithGraphPath:#"me"
parameters:[NSDictionary dictionaryWithObject:#"picture.type(large),id,email,name,username"
forKey:#"fields"]
HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error){[self fbRequestCompleted:result];}];
the "picture" key in the "result" dictionary has the value of the large picture's URL.

You can just use:
http://graph.facebook.com/USER/picture?type=large
Where USER can be either the user id or the user name.
That returns a redirect to the static image url, as written in the User object documentation:
HTTP 302 redirect to URL of the user's profile picture (use
?type=square | small | normal | large to request a different photo).

Nitzan Tomer's response is still correct for iOS; if you want to get the large version of the user's profile picture using Facebook's iOS API, you can just write:
[facebook requestWithGraphPath:#"me/picture" andParams:[NSMutableDictionary dictionaryWithObject:#"large" forKey:#"type"] andDelegate:self];
And you will get the image data in the result object, in this delegate method:
- (void)request:(FBRequest*)request didLoad:(id)result

Related

Getting the user’s Facebook list of friends

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.

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"

Facebook Like/Unlike gives error message

I am building an application which implements Facebook. Through this application I can like and comment on a post. I am fetching Home feeds for the logged in user. Now for Like operation I am using the graph API :
https://graph.facebook.com/POST_ID/likes?&access_token=ACCESS_TOKEN
with HTTPMethod: POST
Here, the POST_ID is the ID I am getting for each feed and the access token of the logged in user.
Now in most of the cases I can like the feed using this API. But some posts don't have Like Connections. How do I know which feed has a like connection & which does not.
Now coming to Unlike. For Unlike operation I am using the graph API :
https://graph.facebook.com/POST_ID/likes?&access_token=ACCESS_TOKEN
with HTTPMethod: DELETE
I can unlike some posts or feeds using this API. But for some I get an error message. In that case i am using for example:
This is the
POST_ID = 12345_67890. When I get error message for this I am using the 67890 as the POST_ID in this case & I am getting success to unlike a post/feed.
Again in using this 67890 as POST_ID gives error in some cases & in that case I am using OBJECT_ID if exists in the feed I am receiving. And I am getting true response in some cases.
But in rest of the cases I can't find any solution for Like & Unlike of a feed/post in Facebook.
Waiting for positive reply.
if you are using correct post_id of feed than it will never produce any error while liking/disliking post on facebook by following code
if do you want to like than change HTTPMethod to POST otherwise set DELETE for dislike. there is no need of accesstoken to call this api.if you are using so it will not produce any error
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:#"%#/likes",#"Post_id"] parameters:nil HTTPMethod:#"DELETE" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (error)
{
NSLog(#"error: %#", error.localizedDescription);
}
else
{
NSLog(#"ok!! %#",result);
}
}];

Facebook api batch request

Now I've got simple request to Facebook api:
me/feed?fields=type,story,caption,message,picture,comments&limit=20&offset=0
It works fine, but in the comments section, there are message, name and user id who post this comment, but I also need a photo-link. Of course I can send more requests to get user-photo. But I think it would be silly decision. Maybe there is way to send fql or batch request to get all fields I need in one request?
P.S. I already know how to do it with ruby, but i need some example which I can use in ios app.
Edit: Also I've got simple example, which do a little more detailed listing, but also without photo. What I should add to request2, to get photo?
JSFacebookRequest *request1 = [JSFacebookRequest requestWithGraphPath:#"me/feed? fields=story,message,comments&offset=15&limit=5"];
[request1 setName:#"get-field"];
JSFacebookRequest *request2 = [JSFacebookRequest requestWithGraphPath:#"?ids={result=get-field:$.data..id}"];
[facebook fetchRequests:[NSArray arrayWithObjects:request1, request2, nil] onSuccess:^(NSArray *responseObjects) {
NSLog(#"Responses:\n%#", responseObjects);
} onError:^(NSError *error) {
NSLog(#"Error: %#", [error localizedDescription]);
}];
Perhaps I'm misunderstanding your situation, but it seems to me that you're over-complicating things. If you've got the user id, you can build the needed URL like so:
https://graph.facebook.com/<user_id>/picture
If that doesn't give you the desired image size, there are other options listed here. (See the 'images' parameter, for example.)

Resources