检查发布到 Facebook feed 是否成功

发布于 2024-11-11 17:29:15 字数 205 浏览 0 评论 0原文

在我的应用程序中,用户可以发布到他的 Facebook feed,我需要知道发布是否成功。在 Facebook 开发者页面上,我发现如果帖子成功,应用程序会收到一个 post_id。所以我可以检查这个 post_id;如果不是nil,这意味着用户已发布到他的提要,但我如何获取post_id

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 has posted to his feed, but how can I get the post_id?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

给妤﹃绝世温柔 2024-11-18 17:29:15

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

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

I used something a little simpler:

if ([url query] != nil) { // eg. post_id=xxxxxxx
    // success
}
时光与爱终年不遇 2024-11-18 17:29:15

当墙柱对话框出现时,用户有 3 个选项。跳过、发布和取消(右上角的小“x”)。这是您可以期待的。

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

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

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

fbconnect://成功

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

fbconnect://success/?post_id=123456789_12345678912345678

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

post_id=_

取消 -
当用户点击取消时,对话框调用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]);   
}

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]);   
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文