3

谢谢阅读!

我正在尝试创建一个 Facebook 请求,以使用户能够邀请他的朋友加入该应用程序。

 NSDictionary *params = [[NSDictionary alloc] initWithObjectsAndKeys:nil];

        [FBWebDialogs
         presentRequestsDialogModallyWithSession:nil
         message:@"Learn how to make your iOS apps social."
         title:@"Test"
         parameters:params
         handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
             if (error) {
                 // Error launching the dialog or sending the request.
                 NSLog(@"Error sending request.");
             } else {
                 if (result == FBWebDialogResultDialogNotCompleted) {
                     // User clicked the "x" icon
                     NSLog(@"User canceled request.");
                 } else {
                     // Handle the send request callback
                     NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
                     if (![urlParams valueForKey:@"request"]) {
                         // User clicked the Cancel button
                         NSLog(@"User canceled request.");
                     } else {
                         // User clicked the Send button
                         NSString *requestID = [urlParams valueForKey:@"request"];
                         NSLog(@"Request ID: %@", requestID);
                     }
                 }
             }
         }];    

}

这几乎是 Facebook 文档代码的干净副本。它可以在一定程度上发挥作用 用户可以选择朋友,请求消失并被朋友接收,并显示为通知 - 到目前为止一切都很好。

问题是,当我尝试从“处理程序”获取响应时,它resultURL是 nil 并且不包含任何内容。之后我收到日志消息“用户取消请求”。

为什么我什么都拿不回来?我需要这个的主要原因是我需要知道请求发送给了哪些朋友。

感谢您的任何帮助!

4

2 回答 2

0

我认为您没有打开会话。请尝试使用它来打开会话。

if (!FBSession.activeSession.isOpen) {
        // if the session is closed, then we open it here, and establish a handler for state changes
            [FBSession openActiveSessionWithReadPermissions:nil
                                               allowLoginUI:YES
                                          completionHandler:^(FBSession *session,
                                                                 FBSessionState state,
                                                                 NSError *error) {
     }];
    }
于 2013-06-18T10:53:11.367 回答
0

好像你正在传递一个 nil 空会话presentRequestsDialogModallyWithSession

改为使用FBSession.activeSession并检查您是否有足够的权限来运行请求(尽管如果没有,您将收到另一个不同的错误)

于 2013-05-28T15:32:08.143 回答