简体   繁体   English

iOS 7-Facebook:检查共享结果

[英]iOS 7 - Facebook: check share result

Have you ever had the needing of check if a share on Facebook wall is done successfully? 您是否需要检查Facebook墙上的共享是否成功完成?

I'd like to know if the user cancels the share operation from the interface of the SDK or if it is not published due a technical issue. 我想知道用户是否从SDK的界面取消了共享操作,或者由于技术问题而未发布共享操作。

I'm using FBDialogs of the framework "FacebookSDK/FacebookSDK.h" on iOS 7. 我在iOS 7上使用框架“ FacebookSDK / FacebookSDK.h”的FBDialogs

The handler block of methods like presentShareDialogWithPhotoParams is never called. 永远不会调用诸如presentShareDialogWithPhotoParams之类的方法的处理程序块。

Thanks in advance. 提前致谢。 Ciao. 再见。

When you present the feed dialog you can use the following code, to detect when user share the post successfully, when user cancel the action or when an error occurs: 显示提要对话框时,可以使用以下代码来检测用户何时成功共享帖子,何时取消操作或何时发生错误:

[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);
                                                      }
                                                  }
                                              }
                                          }];

and when you present the share dialog you can let the following error that comes from server to handle when the post have been shared successfully or not: 当您显示分享对话框时,可以让服务器成功处理以下错误,无论帖子是否成功共享:

[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);
                                      }
                                  }];

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

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