简体   繁体   English

iOS SDK 好友 Facebook API v2.0

[英]iOS SDK Mutual Friends Facebook API v2.0

I'm currently using the Facebook iOS SDK v3.16, which uses the Graph API 2.0.我目前正在使用 Facebook iOS SDK v3.16,它使用 Graph API 2.0。 My call looks like this:我的电话是这样的:

 NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                        @"context.fields(mutual_friends)", @"fields",
                        nil
                        ];
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@"/%@", object[@"profile"][@"facebookId"]]
                             parameters:params
                             HTTPMethod:@"GET"
                      completionHandler:^(
                                          FBRequestConnection *connection,
                                          id result,
                                          NSError *error
                                          ) {
                          cell.text3.text = [NSString stringWithFormat:@"Mutual Users: %lu", [result[@"context"][@"mutual_friends"][@"data"] count]];
                      }];

object[@"profile"][@"facebookId"] is a scoped ID for the app. object[@"profile"][@"facebookId"]是应用程序的范围 ID。

The expected behavior for this call would be to return the number of mutual friends in between the current user and the requested user.此调用的预期行为是返回当前用户和请求用户之间共同好友的数量。 The thing is, though, that the mutual friend count is almost always 0 (for some reason it is 2 in a couple cases, but it should actually be higher).但是,问题是共同朋友的数量几乎总是 0(出于某种原因,在某些情况下它是 2,但实际上应该更高)。

The weird part is the error object never has anything in it, and the result object is just nil.奇怪的部分是错误对象从来没有任何东西,结果对象只是零。 I'm not quite sure how to proceed since there are no results being returned and yet there should be, but it is not giving me an error.我不太确定如何继续,因为没有返回结果,但应该有,但它并没有给我一个错误。

Find a working code in swift 3.0在 swift 3.0 中查找工作代码
Note: Submit for review to facebook for using this service注意:使用此服务需提交至 facebook 审核

FBSDKGraphRequest(graphPath: fbTokenID, parameters: ["fields": "context.fields(mutual_friends.limit(8))"]).start(completionHandler: { (connection, result, error) -> Void in
            if (error == nil){

                print("//////Mutual friends")
                print(result!)

            } else {
                print(error!.localizedDescription)
            }
        })

// you can also limit result of mutual friends by adding "limit" // 您还可以通过添加“限制”来限制共同好友的结果

In swift 3.0在快速 3.0

FBSDKGraphRequest(graphPath:"/me/taggable_friends", parameters:["fields":"user_id,first_name,last_name,name,picture.type(large)"],httpMethod: "GET")
                //["fields": "id, name, first_name, last_name, picture.type(large), email"])
                .start(completionHandler: { (connection,result, error) -> Void in
                if (error == nil)
                {
                    print("Friends are: \(result)")
                    let jsonResult = result as! Dictionary<String,AnyObject>
                    self.dict = jsonResult["data"] as! [AnyObject]

                    for item in self.dict
                    {
                       // let id = item["id"] as! String
                        let name = item["name"] as! String
                        self.FBNameArray.append(name)
                        print("FBname: \(self.FBNameArray)")
                        let picture = item["picture"] as! NSDictionary
                        let parsePic = picture["data"] as! NSDictionary
                        let url = parsePic["url"] as! String
                        self.FBImageArray.append(url)
                        print("FBimage: \(self.FBImageArray)")
                        self.TblView.reloadData()
                    }

                }

            })

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

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