我正在获取使用Facebook登录功能的用户好友列表。在GraphAPI的 "user_freinds" 请求,我请求获取用户的id,email & 名字。然而,API并没有返回用户的电子邮件,只返回了用户的名字和ID。只有用户的名字和ID被返回。请检查下面的代码。
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
}
}
}
}
是否有什么我遗漏的地方?
另外请注意,我使用的是Facebook的测试用户,由Facebook的开发者门户创建。好友的添加和授权只通过开发者门户。
看一看 文件 你缺少 user_friends
需要添加的权限。