2

I am using firebase to login a user through facebook. This all works fine and I can get the users FB profile image, although it is to small. Can somebody tell me how to get a larger one, the code I am using:

     override func viewDidLoad() {
            let loginButton = FBSDKLoginButton()
            loginButton.readPermissions = ["public_profile", "email"]
            loginButton.delegate = self
            self.view.addSubview(loginButton) 
        }

func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError?) {

        let credential = FIRFacebookAuthProvider.credentialWithAccessToken(FBSDKAccessToken.currentAccessToken().tokenString)

            FIRAuth.auth()?.signInWithCredential(credential) { (user, error) in
                if let user = FIRAuth.auth()?.currentUser {
                for profile in user.providerData {
                let photoUrl = profile.photoURL?.absoluteString //SMALL IMAGE
                   }
                }
            }
        }

(This is done in swift)

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Henry Brown
  • 2,219
  • 8
  • 31
  • 48

3 Answers3

2

Once the FB user authenticates, make a FBSDKGraphRequest using FBSDKGraphRequestConnection to get the users FBid, using which you can get the users profile picture by pluggin the id here:

https://graph.facebook.com//picture?type=large&return_ssl_resources=1

instead of type=large you can use ?width=<width>&height=<height> too

too

Ravi Vyas
  • 12,212
  • 6
  • 31
  • 47
1

Once you get the photo Url, just add "?width=400&height=400" to the photo url. Here, height=width=400, you can choose your own height and width. It surely works!

Maverick7
  • 1,087
  • 12
  • 22
-2

According to the Facebook documentation on Profile Picture, you should be able to specify the size by appending width and height to the url:

let photoUrl = profile.photoURL?.absoluteString + "?width=\(width)&height=\(height)"

or by specifying the type:

let photoUrl = profile.photoURL?.absoluteString + "?type=large"
W.K.S
  • 9,787
  • 15
  • 75
  • 122
  • 4
    This is correct if you want to retrieve a picture with facebook API, but he is asking to do it through firebase and if you attach + "?type=large" or + "?width=\(width)&height=\(height)", the page is empty (no picture) – Andrea.Ferrando Oct 07 '16 at 10:55