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

前端 未结 10 1278
天涯浪人
天涯浪人 2021-01-31 03:51

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

FBSession.openActiveSessionWithReadPermissions(         


        
10条回答
  •  天涯浪人
    2021-01-31 04:46

    @Brandon Gao solution gave me a 200X200 thumbnail... To get a bigger size I used FBSDKProfile to get a path with size, that is also more modular and not hard-coded (although I did have to type in the graph.facebook.com part...)

    let size = CGSize(width: 1080, height: 1080)
    let path = FBSDKProfile.currentProfile().imagePathForPictureMode(.Normal, size: size)
    let url = "https://graph.facebook.com/\(path)"
    Alamofire.request(.GET, url, parameters: nil, encoding: ParameterEncoding.URL).response { 
        (request, response, data, error) -> Void in
        if  let imageData = data as? NSData,
            let image = UIImage(data: imageData) {
                self.buttonImage.setImage(image, forState: .Normal)
        }
    }
    

    Somehow I didn't get a 1080X1080 image though, FB gave me a 1117X1117... :\

提交回复
热议问题