skip to Main Content

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


  1. Looking on the docs you are missing user_friends permission which needs to be added.

    Login or Signup to reply.
    1. Use Graph API Explorer to debug: https://developers.facebook.com/tools/explorer/
    2. Try to get permissions: ‘GET/{user-id}/permissions’
    3. Try to get friends list and separate user info in this tool
    4. Email couldn’t be visible if user hides it on privacy settings page
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search