How to get list of all Facebook Friends when using Parse?

冷暖自知 提交于 2019-12-05 07:21:54

问题


Following is the output when getFBfriends() is run in the code inside viewDidAppear below:

Output:

Result Dict: {
    data =     (
    );
    summary =     {
        "total_count" = 711;
    };
}
Found 0 friends

The "total_count = 711" is correct but there is not data about the friends. What I am I missing here? Think the permissions are correct.

Code:

class SignUpViewController: UIViewController {
@IBOutlet weak var btn_signIn: UIButton!
@IBAction func action_btnSignIn(sender: AnyObject) {

    var permissions = ["public_profile", "user_friends"]

    println("in action_btnSignIn() of SignUpViewController")


    var fbloginView:FBLoginView = FBLoginView(readPermissions: ["email", "public_profile", "user_friends"])

override func viewDidAppear(animated: Bool) {
    if PFUser.currentUser() != nil {
        println("User logged in, so launching Menu Screen")
        //self.performSegueWithIdentifier("launchmenu", sender: self)
        getDBfriends()
    } else {
        println("User NOT logged in")
    }

}
func getDBfriends() {
    var friendsRequest: FBRequest = FBRequest.requestForMyFriends()
    friendsRequest.startWithCompletionHandler{(connection:FBRequestConnection!, result:AnyObject!, error:NSError!) -> Void in
        var resultdict = result as NSDictionary
        println("Result Dict: \(resultdict)")
        var data : NSArray = resultdict.objectForKey("data") as NSArray

        for i in 0..<data.count {
            let valueDict : NSDictionary = data[i] as NSDictionary
            let id = valueDict.objectForKey("id") as String
            println("the id value is \(id)")
        }

        var friends = resultdict.objectForKey("data") as NSArray
        println("Found \(friends.count) friends")
    }
}

}

回答1:


Your permissions are correct, but try to login your app using another fb account you will get that user details in your data response.




回答2:


Since v2.0 of the Graph API, you can only get the friends who authorized your App too. The result is correct, none of your friends authorized your App yet so it´s empty and only showing the total amount of friends.

More information: Get ALL User Friends Using Facebook Graph API - Android



来源:https://stackoverflow.com/questions/29466473/how-to-get-list-of-all-facebook-friends-when-using-parse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!