检查发布到Facebook Feed的成功

时间:2011-06-01 17:45:46

标签: objective-c cocoa-touch ios facebook

在我的应用中,用户可以发布到他的Facebook Feed,我需要知道发布是否成功。在Facebook开发人员的页面上,我发现如果帖子成功,该应用会收到post_id。所以我可以查看post_id;如果不是nil这意味着用户已发布到他的Feed,但我怎样才能获得post_id

2 个答案:

答案 0 :(得分:6)

我使用了一些更简单的东西:

if ([url query] != nil) { // eg. post_id=xxxxxxx
    // success
}

答案 1 :(得分:4)

当墙贴文件对话框出现时,用户有3个选项。 Skip,Publish&取消(右上方的小'x')..这是你可以期待的。

下面描述的这些方法是FBDialogDelegate协议的一部分。

该对话框调用dialogCompleteWithUrl:方法,然后调用dialogDidComplete:方法

跳过 - 当用户点击Skip时,传递给dialogCompleteWithUrl:方法的url是

  

fbconnect://success

发布 - 当用户点击发布时,传递给dialogCompleteWithUrl:方法的网址是

  

fbconnect://success/?post_id=123456789_12345678912345678

其中“123456789_12345678912345678”是用户帖子唯一的帖子ID(意思是,这个post_id只是一个例子)。为了更好地解释post_id,post_id参数由userIdentifier和postIdentifier组成。

  

post_id=<userIdentifier>_<postIdentifier>

取消 - 当用户点击取消时,对话框调用dialogCancelWithUrl:方法,然后调用dialogCancel:方法。在下面的示例中,我没有对此调用做任何事情。

*由于我没有使用post_id进行任何操作,除了确定是否有一个用于验证帖子是否成功,下面是如何区分这两个结果的示例。这只是一个示例,可帮助您查看上述结果。随意添加你的演绎*

#pragma mark -
#pragma mark - FBDialogDelegate -
/* ====================================================================*/

/*** Called when the dialog succeeds with a returning url.*/
- (void)dialogCompleteWithUrl:(NSURL *)url {
    NSLog(@"Post Complete w/ URL");     

    NSLog(@"%@",[url absoluteString]);
    NSString *theURLString = [url absoluteString];

    NSString *successString = @"fbconnect://success?post_id=";
    NSString *skipString = @"fbconnect://success";

    NSString *subStringURL = nil;
    if ([theURLString length] > [successString length]) {
        subStringURL = [[url absoluteString] substringToIndex:28];
        NSLog(@"%@",subStringURL);        
    }

    if ([subStringURL isEqualToString:successString] ) 
    {
        UIAlertView *successAlert = [[UIAlertView alloc] initWithTitle:@"Wall Post Successful" message:@"" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
        [successAlert show];
        [successAlert release];
    } 

    if ([theURLString isEqualToString:skipString]) {

        UIAlertView *successAlert = [[UIAlertView alloc] initWithTitle:@"Wall Post Skipped" message:@"" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
        [successAlert show];
        [successAlert release];         
    }

}

/*** Called when the dialog succeeds and is about to be dismissed.*/
- (void)dialogDidComplete:(FBDialog *)dialog {
    NSLog(@"Post Complete");
}

/*** Called when the dialog is cancelled and is about to be dismissed. */
- (void)dialogDidNotComplete:(FBDialog *)dialog {    
    NSLog(@"Post Cancelled");
}

/*** Called when the dialog get canceled by the user.*/
- (void)dialogDidNotCompleteWithUrl:(NSURL *)url {
    NSLog(@"Post Cancelled w/ URL");    
    NSLog(@"%@",[url absoluteString]);   
}