FacebookSDK(4.1.x) Custom Login UI Button - Swift(1.2)
Login with custom button and access token.
Get user info in facebook sdk 4.x
Swift
@IBAction func btnFBLoginPressed(sender: AnyObject) {
var fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
fbLoginManager.logInWithReadPermissions(["email"], fromViewController: self, handler: { (result, error) -> Void in
if (error == nil){
var fbloginresult : FBSDKLoginManagerLoginResult = result
if(fbloginresult.grantedPermissions.contains("email"))
{
self.getFBUserData()
fbLoginManager.logOut()
}
}
})
}
func getFBUserData(){
if((FBSDKAccessToken.currentAccessToken()) != nil){
FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, picture.type(large), email"]).startWithCompletionHandler({ (connection, result, error) -> Void in
if (error == nil){
println(result)
}
})
}
}
iOS facebookSDK get user full details
As per the new Facebook SDK, you must have to pass the parameters with the FBSDKGraphRequest
if((FBSDKAccessToken.currentAccessToken()) != nil){
FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, email"]).startWithCompletionHandler({ (connection, result, error) -> Void in
if (error == nil){
println(result)
}
})
}
Documentations Link : https://developers.facebook.com/docs/facebook-login/permissions/v2.4
User object reference : https://developers.facebook.com/docs/graph-api/reference/user
With public profile you can get gender :
public_profile (Default)
Provides access to a subset of items that are part of a person's public profile. A person's public profile refers to the following properties on the user object by default:
id
name
first_name
last_name
age_range
link
gender
locale
timezone
updated_time
verified
Related Topics
Error Setting Text in Collection View Cell
Supporting Multiple Screen Sizes in Storyboards (3.5 and 4 Inch Screens)
Sending Current Location to Server in Background as Well as in Running App Using Afnetworking 3
Retrieving Data Using Firebase Swift
Dynamic Collectionviewcell in Tableviewcell Swift
Seed and Maintain Cloudkit Public Database Without Requiring Icloud Login
Fairplay Streaming: Calling Copypixelbufferforitemtime on Avplayeritemvideooutput Returns Null
Incorrect Height Calculation with Draggesture() in Swiftui
"Invalid Predicate: Nil Rhs" for Second Argument in Nspredicate Format
How to Change Color of Text Strings Inside Uitextview in Swift3
iOS Apns "Best-Effort" Fallback
How to Launch an App in Foreground When I Enter an Ibeacon Range
Cgcolorgetcomponents() Not Returning the Correct Values for Black and for White