0

Have you ever had the needing of check if a share on Facebook wall is done successfully?

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.

I'm using FBDialogs of the framework "FacebookSDK/FacebookSDK.h" on iOS 7.

The handler block of methods like presentShareDialogWithPhotoParams is never called.

Thanks in advance. Ciao.

Larme
  • 24,190
  • 6
  • 51
  • 81

1 Answers1

1

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