I’m fetching the list of user’s friends who all are using the application with Login with Facebook feature. In GraphAPI for “user_freinds” request, I’m requesting for id, email & name of the users. However the API is not returning the email of users. Only name and ID of users are being returned. Please check the code below.
func getFacebookFriends() {
if AccessToken.current != nil {
let fbUserID = AccessToken.current?.userId ?? ""
let friendsPath = "/(fbUserID)/friends"
let params = ["fields": "id, name, email"]
let fbFriendsRequest = GraphRequest(graphPath: friendsPath, parameters: params, httpMethod: .GET)
fbFriendsRequest.start { (_, result) in
switch result {
case .success(let response):
print(response.dictionaryValue as Any)
let responseDict = response.dictionaryValue!
let data = responseDict["data"] as! [[String:Any]]
if data.count != 0 {
// Sync the list with API
} else {
// Show error
}
case .failed(let error):
// Show error
}
}
}
}
Is there anything I’m missing here?
Also note that I’m using test users of Facebook, created by Developer portal of Facebook. Friends are added and authorised via Developer portal only.
2
Answers
Looking on the docs you are missing
user_friends
permission which needs to be added.