2011-06-01 63 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