开发者

Checking the success of a posting to Facebook feed

In my app user can post to his facebook feed, and I need to know whether the posting was successful or not. On the Facebook developers' page, I found that if a post is successful, the app receives a post_id. So I can check this post_id; if it is not nil this means the user h开发者_运维技巧as posted to his feed, but how can I get the post_id?


I used something a little simpler:

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


There are 3 options a user has when the wall post dialog is present. Skip, Publish & Cancel (the little 'x' at on top right).. Here is what you can expect.

These methods described below are part of the FBDialogDelegate Protocol.

The dialog calls dialogCompleteWithUrl:method and then it calls the dialogDidComplete:method

SKIP - When the user taps Skip, the url that is passed to the dialogCompleteWithUrl:method is

fbconnect://success

PUBLISH - When the user taps Publish, the url that is passed to the dialogCompleteWithUrl:method is

fbconnect://success/?post_id=123456789_12345678912345678

where "123456789_12345678912345678" is the post id unique to the user's post (meaning, this post_id is just an example). To better explain the post_id, the post_id parameter consists of userIdentifier and the postIdentifier.

post_id=<userIdentifier>_<postIdentifier>

CANCEL - When the user taps on the Cancel the dialog calls the dialogCancelWithUrl:method, then the dialogCancel:method. I am not doing anything with this call in the example below.

*Since I am not using the post_id for anything except to determine if one is present to validate the success of the post, below is an example of how to differentiate the two results. This is just an example, to assist you in seeing the results as described above. Feel free to add your rendition*

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜