Benny
Benny

Reputation: 5092

iPhone Facebook SDK 3 get user details & profile pic in one request

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.

Upvotes: 1

Views: 5802

Answers (2)

jpotts18
jpotts18

Reputation: 5111

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:

Upvotes: 0

Benny
Benny

Reputation: 5092

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) {

                  }];

Upvotes: 7

Related Questions