2

我正在尝试使用适用于 iOS 的 FB SDK 获取我朋友的家乡和位置。但我无法检索朋友的位置和家乡。这是我的代码

    - (IBAction)btnFBLoginTapped:(id)sender {

    NSArray *permissions = [[NSArray alloc]initWithObjects:@"email",@"user_birthday",@"user_hometown",@"user_location",@"friends_birthday",@"friends_location",@"friends_hometown", nil];

    [FBSession openActiveSessionWithPermissions:permissions allowLoginUI:YES
                              completionHandler:^(FBSession *session,
                                                  FBSessionState status,
                                                  NSError *error) {
                                  // session might now be open.
                                  if (session.isOpen) {
                                      FBRequest *me = [FBRequest requestForMe];
                                      [me startWithCompletionHandler: ^(FBRequestConnection *connection, 
                                                                        NSDictionary<FBGraphUser> *my,
                                                                        NSError *error) {
                                          NSLog(@"My dcitionary:- %@",my);
                                          NSLog(@"Sessionkey:- %@",session.accessToken);
                                          // Friend request

                                          FBRequest *friendRequest = [FBRequest requestForMyFriends];

                                          [friendRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                                              NSDictionary *resultDictionary = (NSDictionary *)result;

                                              NSArray *data = [resultDictionary objectForKey:@"data"];

                                              NSLog(@"Data:- %@",data);

                                              for (NSDictionary *dic in data) {
                                                  NSLog(@"ID:- %@",[dic objectForKey:@"id"]);
                                              }
                                          }];
                                      }];
                                  }
                              }];
}

我还需要检索朋友的生日。但我也无法检索生日。

有人可以帮忙吗?

4

2 回答 2

3

data是一个数组FBGraphObject<FBGraphUser>

[friendRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
    NSArray *data = [result objectForKey:@"data"];

    for (FBGraphObject<FBGraphUser> * user in data) {
        NSLog(@"%@", [user first_name]);
    }
...
于 2012-10-10T21:24:53.880 回答
0

此时检查您的逻辑

....
[friendRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
     NSDictionary *resultDictionary = (NSDictionary *)result;

您的结果应该是 NSArray,而不是 NSDictionary。

仔细检查结果的另一件事是在 Graph API 资源管理器中放置一个类似的查询:https ://developers.facebook.com/tools/explorer

您可以将我/朋友放在 Graph API 资源管理器中提示:选择您在 Graph API 资源管理器的应用程序下拉列表中设置的相同应用程序。

于 2012-09-27T00:43:59.640 回答