Facebook iOS SDK and swift: how get user's profile picture

Tom picture Tom · Jan 25, 2015 · Viewed 47.1k times · Source

i have integrated Facebook sdk in Xcode 6 (with swift). During the login i request the public_profile permission:

FBSession.openActiveSessionWithReadPermissions(["public_profile"], allowLoginUI: true, completionHandler: {
...
...

So i request the user's information:

FBRequestConnection.startForMeWithCompletionHandler { (connection, user, error) -> Void in
...
...

Why the user object doesn't contain the profile picture? How can i get the user profile picture? It's not part of the public_profile?

I get the following information:

2015-01-25 01:25:18.858 Test[767:23804] {
"first_name" = xxx;
gender = xxx;
id = xxxxxxxxx;
"last_name" = xxxxxx;
link = "https://www.facebook.com/app_scoped_user_id/xxxxxxxxx/";
locale = "xxxxx";
name = "xxxxxxx xxxxxxx";
timezone = 1;
"updated_time" = "2013-12-21T18:45:29+0000";
verified = 1;
}

P.S: xxx for privacy

Answer

Lyndsey Scott picture Lyndsey Scott · Jan 25, 2015

The profile picture is in fact public and you can simply by adding the user id to Facebook's designated profile picture url address, ex:

var userID = user["id"] as NSString     
var facebookProfileUrl = "http://graph.facebook.com/\(userID)/picture?type=large"

This particular url address should return the "large" version of the user's profile picture, but several more photo options are available in the docs.