2017-03-10 140 views
-1

所以我試圖從Facebook獲取朋友列表,但每次它崩潰。這是我的代碼...Swift 3:Facebook獲取朋友列表

FBSDKGraphRequest(graphPath: "/me", parameters: ["fields": "id, name, friends"]).start { (connection, result, error) in 

     if error != nil{ 
      print(error!) 
      return 
     } 

     let Result: [String: String] = result as! [String : String] 

     // setting name // 
     self.NameField.text = Result["name"]! 
     print(Result["friends"]!) 
} 

回答

0

在這裏,你得到它已經使用你的應用程序和它的極限100可以改變限制爲您的要求的朋友。

let request = FBSDKGraphRequest.init(graphPath: "me", parameters: ["fields": "id,name,about,gender,birthday,email,picture,friends.limit(100){picture,name}"], httpMethod: "GET") 
_ = request?.start(completionHandler: {(connection, result, error) in 
     DispatchQueue.main.async { 
      print("....FBSDKRequest User Details....", result ?? "") 
      if error == nil { 
       let dic = result as! NSDictionary 
       completion(dic,nil) 
      } 
      else { 
       let err = error as! NSError 
       completion(nil,err) 
      } 
    } 
})