您是否有过检查 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/