The permission of Facebook post is “Only me” using FBWebDialogs

大憨熊 提交于 2020-01-13 19:48:29

问题


I want to post text and link from iOS app to user timeline. I copy and paste FBWebDialogs example.

Problem 1: The post appear in my timeline but the permission is "Only me", not friend or public.

Problem 2: The result object (FBWebDialogResult) is nil. Log appear in my console.NSLog(@"User canceled story publishing.");

Problem 3: The permission of preview box is "only me" even I set it to public

Attached setting of my Facebook page:

Here is my code:

[FBWebDialogs presentFeedDialogModallyWithSession:nil
                                       parameters:params
                                          handler:
 ^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
     if (error) {
         // Error launching the dialog or publishing a story.
         NSLog(@"Error publishing story.");
     } else {
         if (result == FBWebDialogResultDialogNotCompleted) {
             // User clicked the "x" icon
             NSLog(@"User canceled story publishing.");
         } else {
             // Handle the publish feed callback
             NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
             if (![urlParams valueForKey:@"post_id"]) {
                 NSLog(@"User canceled story publishing.");
             } else {
                 NSString *msg = [NSString stringWithFormat:
                                  @"Posted story, id: %@",
                                  [urlParams valueForKey:@"post_id"]];
                 [[[UIAlertView alloc] initWithTitle:@"Result"
                                             message:msg
                                            delegate:nil
                                   cancelButtonTitle:@"OK!"
                                   otherButtonTitles:nil]
                  show];
             }
         }
     }
 }];

The setting page of my app is "only me" by default. I don't expect all my users change this setting here.


回答1:


OMG. I stuggled for whole day but no progress. I found solution as soon as I ask question.

The problem is I copied inappropriate sample code. Ichanged to [FBSession openActiveSessionWithPublishPermissions] and problem solved.

Here is the login code I used. My post can be public now.

- (void)buttonRequestClickHandler:(id)sender {
// FBSample logic
// Check to see whether we have already opened a session.
if (FBSession.activeSession.isOpen) {
    // login is integrated with the send button -- so if open, we send
    //  [self sendRequests];
    NSLog(@"Login in facebook");
} else {

      NSArray *permission = [NSArray arrayWithObjects:@"publish_actions", nil];
    [FBSession openActiveSessionWithPublishPermissions:permission defaultAudience:FBSessionDefaultAudienceEveryone allowLoginUI:YES completionHandler:^(FBSession *session,
                                                      FBSessionState status,
                                                      NSError *error) {
                                      // if login fails for any reason, we alert
                                      if (error) {
                                          UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                                                          message:error.localizedDescription
                                                                                         delegate:nil
                                                                                cancelButtonTitle:@"OK"
                                                                                otherButtonTitles:nil];
                                          [alert show];
                                          // if otherwise we check to see if the session is open, an alternative to
                                          // to the FB_ISSESSIONOPENWITHSTATE helper-macro would be to check the isOpen
                                          // property of the session object; the macros are useful, however, for more
                                          // detailed state checking for FBSession objects
                                      } else if (FB_ISSESSIONOPENWITHSTATE(status)) {
                                          // send our requests if we successfully logged in
                                          NSLog(@"Login in facebook");                                          }
                                  }];
}


来源:https://stackoverflow.com/questions/16291837/the-permission-of-facebook-post-is-only-me-using-fbwebdialogs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!