iOS Facebook Graph API Profile Picture Link

Getting profile picture with swift through Facebook Graph API return unsupported URL

Able to get it using this code:

    // Get user profile pic
var fbSession = PFFacebookUtils.session()
var accessToken = fbSession.accessTokenData.accessToken
let url = NSURL(string: "https://graph.facebook.com/me/picture?type=large&return_ssl_resources=1&access_token="+accessToken)
let urlRequest = NSURLRequest(URL: url!)

NSURLConnection.sendAsynchronousRequest(urlRequest, queue: NSOperationQueue.mainQueue()) { (response:NSURLResponse!, data:NSData!, error:NSError!) -> Void in

// Display the image
let image = UIImage(data: data)
self.imgProfile.image = image

}

Get Facebook API Profile Picture ios Swift

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{

}
}

Get Photo URL Given a Photo ID: Facebook Graph API for iOS (Swift)

let requestPhotos = FBSDKGraphRequest(graphPath:id_num, parameters:["fields":"picture, name, album, place"])

Where id_num is the ID number of the Facebook photo. Very simple.

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

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.

Facebook Graph API batch request for friend's profile picture using iOS?

For all friends ask for /me/friends?fields=name,picture

For mutual friends, ask for /me/mutualfriends/[OTHER ID]/?fields=name,picture

how to fetch profile picture from facebook

If you are able to log in with Facebook, then you should have the FB ID of that user. With that in hand, you can use this for get the profile picture:

func getProfPic(fid: String) -> UIImage? {
if (fid != "") {
var imgURLString = "http://graph.facebook.com/" + fid! + "/picture?type=large" //type=normal
var imgURL = NSURL(string: imgURLString)
var imageData = NSData(contentsOfURL: imgURL!)
var image = UIImage(data: imageData!)
return image
}
return nil
}

You can also change the type parameter to a different size in the URL.

Download high resolution profile image Facebook Graph API

This is what I have to request 200x200 on an iPhone 7 and 300x300 on a plus size. However I don't think you get an image back with those exact sizes. It might be slightly larger.

let deviceScale = Int(UIScreen.main.scale)
let width = 100 * deviceScale
let height = 100 * deviceScale
let parameters = ["fields": "first_name, last_name, picture.width(\(width)).height(\(height))"]

In summary, the syntax for the param to request a 400x400 would be picture.width(400).height(400).

Getting username and profile picture from Facebook iOS 7

This is the simplest way I've found to get the user's profile picture.

[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *FBuser, NSError *error) {
if (error) {
// Handle error
}

else {
NSString *userName = [FBuser name];
NSString *userImageURL = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large", [FBuser objectID]];
}
}];

Other query parameters that can be used are:

  • type: small, normal, large, square
  • width: < value >
  • height: < value >
    • Use both width and height to get a cropped, aspect fill image


Related Topics



Leave a reply



Submit