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

前端 未结 10 1579
天涯浪人
天涯浪人 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:41

    you can use this code For Swift 3.0 to get the user information

      func getFbId(){
    if(FBSDKAccessToken.current() != nil){
    FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id,name , first_name, last_name , email,picture.type(large)"]).start(completionHandler: { (connection, result, error) in
        guard let Info = result as? [String: Any] else { return } 
    
    
        if let imageURL = ((Info["picture"] as? [String: Any])?["data"] as? [String: Any])?["url"] as? String {
            //Download image from imageURL
        }
    if(error == nil){
    print("result")
    }
    })
    }
    }
    

提交回复
热议问题