mankee mankee - 6 months ago 18
iOS Question

Get Facebook API Profile Picture ios Swift

I am using interested in obtaining the following info from a user's fb profile :


  1. email

  2. name

  3. profile picture link

  4. age



To do so I use the following code:

let accessToken = FBSDKAccessToken.currentAccessToken()
let req = FBSDKGraphRequest(graphPath: "me", parameters: ["fields":"picture.redirect(false),email,name,gender,age_range,birthday"], tokenString: accessToken.tokenString, version: nil, HTTPMethod: "GET")
req.startWithCompletionHandler({ (connection, result, error : NSError!) -> Void in
if(error == nil)
{
print("result \(result)")
}
else
{
print("error \(error)")
}
}) }


This returns:

result {
"age_range" = {
min = 21;
};
email = "dedewdd@gmail.com";
gender = male;
id = xxxxxxxxxxxx;
name = "John Smith";
picture = {
data = {
"is_silhouette" = 0;
url = "https://scontent.xx.fbcdn.net/v/t1.0-1/p50x50/dwqdwddqwdwqdw";
};
};
}


The problem with this is that this image is 50X50 pixels, I would like to obtain a link to a larger image.

Answer

So I use Kingfisher to download the image but essentially the NSURL is the key to getting a larger image. IF this doesnt work, then try changing the "50x50" in the url to "250x250" and see if that works

if FBSDKAccessToken.currentAccessToken() != nil {

let userID = FBSDKAccessToken.currentAccessToken().userID

if(userID != nil) //should be != nil
{
print(userID)
}

let URL = NSURL(string: "http://graph.facebook.com/\(userID)/picture?type=large")!

profileImage.kf_setImageWithURL(URL)

}else{

}
}