简体   繁体   English

如何从图形api中显示user_friends数据?

[英]How to show user_friends data from graph api?

I'm making an app on iOs and I allow user to log in with facebook. 我在iOs上制作应用程序,我允许用户使用facebook登录。 I already tested my app on simulator, log in using facebook with 2 account that already friend . 我已经在模拟器上测试了我的应用程序,使用facebook和已经是朋友的2个帐户登录 But when I'm testing my graphpath on https://developers.facebook.com/tools/explorer/145634995501895/ . 但是当我在https://developers.facebook.com/tools/explorer/145634995501895/上测试我的graphpath时。 It shows nothing. 它没有任何表现。

{
  "id": "1001399423222952", 
  "name": "Ega Setya Putra", 
  "friends": {
    "data": [
    ], 
    "summary": {
      "total_count": 1290
    }
  }
}

and here my code on xcode, and again it shows nil 这里是我在xcode上的代码,再次显示为nil

func getDBfriends() {
    let friendsRequest: FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me?fields=id,name,friends", parameters: nil)
    friendsRequest.startWithCompletionHandler{(connection, result: AnyObject!, error) -> Void in
        if let resultdict = result as? NSDictionary{
        println("Result Dict: \(resultdict)")
        var jos = resultdict.objectForKey("data") as! NSArray
        var data : NSArray = jos

        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")
    }
    }
}

I thinks your graph path is wrong.I am using the following path in Objective-c and getting all my friends which are using the app.Let me know if this can help you. 我认为您的图形路径是错误的。我在Objective-c中使用以下路径并获取正在使用该应用程序的所有朋友。让我知道这是否可以帮助您。

NSData * dataFriendsList = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/me/friends?access_token=%@&fields=id,first_name,picture,last_name,name,birthday,gender,location,link,hometown,email,work,education,bio",fbAccessToken]]];

And you have to take user_friends permission from Facebook. 而你必须从Facebook获得user_friends许可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM