iOS 7 - Facebook : check share result

标签 ios objective-c facebook facebook-sdk-3.1

您是否有过检查 Facebook 墙上的分享是否成功的需要?

我想知道用户是从SDK的接口(interface)取消了分享操作还是因为技术问题没有发布。

我在 iOS 7 上使用框架“FacebookSDK/FacebookSDK.h”的 FBDialogs

永远不会调用 presentShareDialogWithPhotoParams 等方法的处理程序 block 。

提前致谢。 再见。

最佳答案

当您显示提要对话框时,您可以使用以下代码来检测用户何时成功共享帖子、何时取消操作或何时发生错误:

[FBWebDialogs presentFeedDialogModallyWithSession:nil
                                       parameters:params
                                          handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
                                              if (error) {
                                                  // An error occurred, we need to handle the error
                                                  // See: https://developers.facebook.com/docs/ios/errors
                                                  NSLog(@"%@", [NSString stringWithFormat:@"Error publishing story: %@", error.description]);
                                              } else {
                                                  if (result == FBWebDialogResultDialogNotCompleted) {
                                                      // User cancelled.
                                                      NSLog(@"User cancelled.");
                                                  } else {
                                                      // Handle the publish feed callback
                                                      NSDictionary *urlParams = [self parseURLParams:[resultURL query]];

                                                      if (![urlParams valueForKey:@"post_id"]) {
                                                          // User cancelled.
                                                          NSLog(@"User cancelled.");

                                                      } else {
                                                          // User clicked the Share button
                                                          NSString *result = [NSString stringWithFormat: @"Posted story, id: %@", [urlParams valueForKey:@"post_id"]];
                                                          NSLog(@"result %@", result);
                                                      }
                                                  }
                                              }
                                          }];

当您显示共享对话框时,您可以让来自服务器的以下错误来处理帖子是否成功共享:

[FBDialogs presentShareDialogWithLink:params.link
                                     name:params.name
                                  caption:params.caption
                              description:params.description
                                  picture:params.picture
                              clientState:nil
                                  handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
                                      if(error) {
                                          // An error occurred, we need to handle the error
                                          // See: https://developers.facebook.com/docs/ios/errors
                                          NSLog(@"%@", [NSString stringWithFormat:@"Error publishing story: %@", error.description]);
                                      } else {
                                          // Success
                                          NSLog(@"result %@", results);
                                      }
                                  }];

关于iOS 7 - Facebook : check share result,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23227398/

相关文章:

javascript - 使用 facebook connect 触发功能

iphone - 带有图像和文本的 UIBarButtonItem

ios - 如何更新 UISegmentedControl

iphone - 如何在 iPhone 上改变 View 时制作溶解动画?

ios - 我是否将相同的对象与 prepareForSegue 传回?

ios - Facebook Developer API iOS,age_range 返回 NULL

ios - 用于 App Store 显示的 CFBundleDevelopmentRegion (info.plist) 的字符串格式

ios/swift - 将 subview 放在 super View 后面?

ios - 如何手动设置 UIDocumentInteractionController 呈现的选项菜单的箭头方向?

java - React-Native Android 构建失败 - 无法找到请求目标的有效认证路径