【发布时间】:2018-04-14 14:12:35
【问题描述】:
了解一点背景知识 - 我有一个“关注 Facebook 朋友”视图控制器,用户可以在其中查看他们的朋友,他们也下载了我的应用以在应用上关注。
我已正确调用 FBSDK 以获取也下载了该应用程序的朋友列表,但现在我需要在 Firebase 中获取这些朋友的 uid,以便我可以相应地关注/取消关注他们。
目前,当我获得 FB 用户 ID 时 - 我获得了 facebook 文档中提到的数字字符串。但是,Firebase 中的用户 uid 是不同的。有没有办法找到与 FB id 相关联的 firebase 用户?或者我应该尝试通过 facebook id 在 firebase 中存储 Facebook 用户?
var facebookContacts = [User]()
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "facebookContactCell", for: indexPath) as! FacebookContactCell
// Configure the cell...
let user = facebookContacts[indexPath.row]
cell.contactNameLabel.text = user.name
cell.userId = user.documentId
// Set follow button state
if followingArray.contains(cell.userId) {
cell.followButton.isSelected = true
} else {
cell.followButton.isSelected = false
}
let userImageRef = storage.child("userImages/"+(user.documentId)+"/profile_pic.jpg")
// Download in memory with a maximum allowed size of 1MB (1 * 1024 * 1024 bytes)
userImageRef.getData(maxSize: 1 * 1024 * 1024) { (data, error) in
if let error = error {
// Uh-oh, an error occurred! Display Default image
print("Error - unable to download image: \(error)")
cell.contactImageView.image = UIImage(named: "userProfileGray")
} else {
// Data for "locationImages/(locationId).jpg" is returned
cell.contactImageView.image = UIImage(data: data!)
}
SVProgressHUD.dismiss()
}
return cell
}
func getFbFriends() {
let params = ["fields": "id, first_name, last_name, name, email, picture"]
let graphRequest = FBSDKGraphRequest(graphPath: "/me/friends", parameters: params)
let connection = FBSDKGraphRequestConnection()
connection.add(graphRequest, completionHandler: { (connection, result, error) in
if error == nil {
let resultdict = result as! NSDictionary
print("Result Dict: \(resultdict)")
let data : NSArray = resultdict.object(forKey: "data") as! NSArray
for i in 0..<data.count {
let valueDict : NSDictionary = data[i] as! NSDictionary
let id = valueDict.object(forKey: "id") as! String
print("the id value is \(id)")
let name = valueDict.object(forKey: "name") as! String
print("the name value is \(name)")
let picDict = valueDict["picture"] as! NSDictionary
let picData = picDict["data"] as! NSDictionary
let picURL = picData.object(forKey: "url") as! String
print("the url value is \(picURL)")
self.facebookContacts.append(User(name: name, documentId: id))
}
DispatchQueue.main.async {
self.tableView.reloadData()
}
let friends = resultdict.object(forKey: "data") as! NSArray
print("Found \(friends.count) friends")
} else {
print("Error Getting Friends \(String(describing: error))");
}
})
connection.start()
}
【问题讨论】:
标签: swift facebook firebase facebook-graph-api google-cloud-firestore