1

我正在开发一个 iPhone 应用程序,如果他们已经授予我的应用程序访问他们的电子邮件的权限,我希望能够列出连接到我的应用程序并访问他们的电子邮件的用户朋友。

这是我用来打开 Facebook 会话的代码:

    - (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {

     NSArray *permissions = [[NSArray alloc] initWithObjects:
                    @"email",
                    nil];

    return [FBSession openActiveSessionWithReadPermissions:permissions
                                      allowLoginUI:allowLoginUI
                                 completionHandler:^(FBSession *session,
                                                     FBSessionState state,
                                                     NSError *error) {
                                     [self sessionStateChanged:session
                                                         state:state
                                                         error:error];
                                 }];
}

此外,在 ViewController.m 中,我使用以下代码列出朋友并获取他们的电子邮件:

    NSString *query =
         [NSString stringWithFormat:@"SELECT name, uid, pic_small, birthday,proxied_email, contact_email , email FROM user WHERE is_app_user = 1 and uid IN (SELECT uid2 FROM friend where uid1 = %@) order by concat(first_name,last_name) asc", my_fb_uid ];

        // Set up the query parameter
       NSDictionary *queryParam =
      [NSDictionary dictionaryWithObjectsAndKeys:query, @"q", nil];
       // Make the API request that uses FQL

    [FBRequestConnection startWithGraphPath:@"/fql"
                         parameters:queryParam
                         HTTPMethod:@"GET"
                  completionHandler:^(FBRequestConnection *connection,
                                      id result,
                                      NSError *error) {
                      if (error) {
                          NSLog(@"Error: %@", [error localizedDescription]);
                      } else {
                          NSLog(@"Result: %@", result);
                      }
                  }];  

问题是返回的电子邮件始终为空,即使对于安装了我的应用程序并授权它访问他们的电子邮件的朋友也是如此。

对此有何建议?

4

2 回答 2

19

文档中:

Note: There is no way for apps to obtain email addresses for a user's friends.

email权限仅适用于已登录用户

于 2013-03-06T23:53:14.387 回答
4

您应该做的是,当用户授予他们 Facebook 帐户的访问权限时,您应该存储他们的 FB 用户 ID。然后在尝试查找用户的朋友时,拉取用户的 FB 朋友的请求(http://developers.facebook.com/docs/reference/ios/3.2/class/FBRequest#requestForMyFriends)并比较返回的 ID。这是做你想做的事情的正确方法。

于 2013-03-07T00:55:52.713 回答