2011-06-01 40 views
2

在我的应用中,用户可以发布到他的Facebook feed中,并且我需要知道发布是否成功。在Facebook开发者的页面上,我发现如果帖子成功,该应用会收到post_id。所以我可以检查这个post_id;如果不是nil这意味着用户已经发布到他的源,但我怎样才能得到post_id检查Facebook邮件发布是否成功

回答

4

当存在挂墙对话框时,用户有3个选项。跳过,发布&取消(右上角的小'x')。以下是您可以期待的内容。

下面介绍的这些方法是FBDialogDelegate协议的一部分。

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

SKIP - 当用户点击跳过,传递给dialogCompleteWithUrl的网址:方法是

fbconnect://success

PUBLISH - 当用户点击发布,传递给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]); 
} 
+1

这太复杂了。 Madmax的回答是正确的。 – SmallChess 2012-09-04 10:03:49

6

我用简单的东西一点点:

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

你在哪里用过它? – Saad 2012-05-31 07:58:08

+1

内部dialogCompleteWithUrl – SmallChess 2012-09-04 10:03:27

相关问题