[英]How to create pointer to Parse PFUser from facebook ID
我正在進行Facebook圖表通話,以結識正在使用我的應用程序的用戶的朋友。 我從圖表調用中獲得了用戶朋友的Facebook ID。 下面是我嘗試從具有該ID的Parse獲取的內容,但是它並沒有讓所有用戶都回來,我相信這是因為它是異步調用。 如何保存正在使用該應用程序的用戶fb朋友的指針數組? 提前致謝!!
graphConnection.addRequest(requestFriends, completionHandler: { (connection: FBSDKGraphRequestConnection!, result: AnyObject!, error: NSError!) -> Void in
if result.objectForKey("friends") != nil {
// parsing dictionary to get results
let firstDict = result.objectForKey("friends")
let dataArray = firstDict!.objectForKey("data")
let myFriendsUsingTheAppCount = dataArray!.count
print("\(myFriendsUsingTheAppCount)")
let friendsArray:NSMutableArray = []
for var i = 0; i < dataArray!.count; i++ {
let friend = dataArray![i]
let friendFbObjectID = friend.objectForKey("id")!
let query = PFUser.query()
query!.whereKey("facebookID", equalTo: friendFbObjectID)
query!.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in
if error == nil {
// this is where I was going to save this specific user as a pointer
} else {
// some error
}
})
// this is saving just the friend's name/fb id to an array, but I want an array of pointers to the PFUser
friendsArray.addObject(friend)
}
} else {
// fb friends is nil
print("FB friends came back nil")
}
})
使用whereKey:containedIn:
可以將其簡化為單個查詢whereKey:containedIn:
let facebookIDs = dataArray.map { $0.objectForKey("id")! }
let query = PFUser.query()!
query.whereKey("facebookID", containedIn: facebookIDs)
現在,查詢將包含其Facebook ID在傳遞給查詢的數組中的所有用戶。
(swift語法可能不正確,沒有仔細檢查)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.