I have used the SLRequest
for getting profile info and i followed the Getting user profile picture in iOS6? to get the profile image. But it returning 50x50
image dimension. I need large size of profile picture. Can anyone give me some idea to do this using SLRequest
?
3 Answers
use the below URL to get the large image:
https://graph.facebook.com/fb_user_id/picture?type=large
For cover image, use the below:
http://graph.facebook.com/fb_user_id?fields=cover
this will return:
{
"cover": {
"id": "XXX",
"source": "cover_image_url",
"offset_y": 66
},
"id": "XXXXXX"
}

- 1,590
- 10
- 13
-
can you please give me the url for getting cover image from facebook? – Surfer Mar 05 '14 at 04:44
-
this returning error `(#100) type must be one of the following values: small, normal, large, square` – Surfer Mar 05 '14 at 06:33
-
is the error for cover image or profile picture? because type value is already `large` (i.e. one of the values requested) ! – MuhammadBassio Mar 05 '14 at 09:12
-
i fixed that error ... thanks. is it possible to get the profile image as in url format? – Surfer Mar 05 '14 at 12:27
-
currently profile image is getting as `NSData`. But i need URL for Profile image – Surfer Mar 06 '14 at 12:00
-
the returned NSData is the image data, just use `UIImage *profimage = [UIImage imageWithData:retrievedData];` – MuhammadBassio Mar 06 '14 at 17:21
You can get the large image of profile picture as
[NSURL URLWithString:@"https://graph.facebook.com/me/picture?type=large"];
The type parameter supports
enum{square,small,normal,large}

- 3,391
- 1
- 19
- 32
Here is the answer for swift 3.
you have to get the access to the facebook account of the user in his or her device, this using accountStore API:
func accessFacebookAccount(onCompletion: @escaping(_ tokenCredential: String, _ facebookAccount: ACAccount) -> Void, onError: @escaping (_ errorMessage: String?) -> Void) { let accountStore = ACAccountStore() let facebookAccountType = accountStore.accountType(withAccountTypeIdentifier: ACAccountTypeIdentifierFacebook) let options = [ "ACFacebookAppIdKey" : "529210493918001", "ACFacebookPermissionsKey" : ["email","public_profile"], "ACFacebookAudienceKey" : ACFacebookAudienceOnlyMe] as [String : Any] accountStore.requestAccessToAccounts(with: facebookAccountType, options: options) { (granted, error) in if granted { let fbAccount = accountStore.accounts(with: facebookAccountType).last as? ACAccount let credential = fbAccount?.credential let token = credential?.oauthToken onCompletion(token!, fbAccount!) } else { let error = "Access to Facebook was not granted." onError(error) } } }
Once you get the response, and the user granted the access to the account. You can make use of the ACAccount object and access the facebook info via a SLRequest:
func getFacebookInfoViaAccounts (_ fbAccount: ACAccount) { let myURL = URL(string: "https://graph.facebook.com/me") let request = SLRequest.init(forServiceType: SLServiceTypeFacebook, requestMethod: .GET, url: myURL, parameters: ["fields":"email, first_name, last_name,birthday, gender"]) request?.account = fbAccount request?.perform(handler: { (dataResponse, urlResponse, error) in if error == nil { let json = try? JSONSerialization.jsonObject(with: dataResponse!, options: [ JSONSerialization.ReadingOptions.allowFragments]) if let dict = json as? [String: Any] { print("My data \(dict)") } } }) let myPhotoURl = URL(string: "https://graph.facebook.com/me/picture") let requestPhoto = SLRequest.init(forServiceType: SLServiceTypeFacebook, requestMethod: .GET, url: myPhotoURl, parameters: ["type":"large"]) requestPhoto?.account = fbAccount requestPhoto?.perform(handler: { (dataResponse, urlResponse, error) in if error == nil { print("URL DE LA PHOTO \(urlResponse?.value(forKey: "URL"))") } }) }
Above is the code for getting the image of the users profile and the info, like email, gender and birthday.
This is the way apps like tinder get your data and dont request the user to log in to the facebook account, if the user has his facebook account linked to his or her iphone.
I hope this helps somebody, happy coding :).

- 583
- 7
- 11