Not able to post on Facebook using Facebook sdk in iOS 7

258 Views Asked by At

I am getting an issue while posting a feed on Facebook using Facebook sdk in ios7.

I have copied the code from Facebook samples provided on Github. But whenever I tried to post on Facebook, a message appears as "An error occurred. Please try again later". And then I have to close the web view. Please find the code below: NSMutableDictionary *params123 = [NSMutableDictionary dictionaryWithObjectsAndKeys: @"Roasted pumpkin seeds", @"name", @"Healthy snack.", @"caption", @"Crunchy pumpkin seeds roasted in butter and lightly salted.", @"description", @"http://example.com/roasted_pumpkin_seeds", @"link", @"https://i.stack.imgur.com/fiRtu.png", @"picture", nil];

    // Show the feed dialog
    [FBWebDialogs presentFeedDialogModallyWithSession:nil
                                           parameters:params123
                                              handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
                                                  if (error) {
                                                      // An error occurred, we need to handle the error
                                                      // See: https://developers.facebook.com/docs/ios/errors
                                                      NSLog(@"Error publishing story: %@", error.description);
                                                  } else {
                                                      if (result == FBWebDialogResultDialogNotCompleted) {
                                                          // User cancelled.
                                                          NSLog(@"User cancelled.");
                                                      } else {
                                                          // Handle the publish feed callback
                                                          NSDictionary *urlParams = [self parseURLParams:[resultURL query]];

                                                          if (![urlParams valueForKey:@"post_id"]) {
                                                              // User cancelled.
                                                              NSLog(@"User cancelled.");

                                                          } else {
                                                              // User clicked the Share button
                                                              NSString *result = [NSString stringWithFormat: @"Posted story, id: %@", [urlParams valueForKey:@"post_id"]];
                                                              NSLog(@"result %@", result);
                                                          }
                                                      }
                                                  }
                                              }];

}

Note: I am using the updated version of Facebook sdk for iOS 7

1

There are 1 best solutions below

0
On

Why do you use a webdialog ?

Here is what I use

NSArray *urlsArray = [NSArray arrayWithObjects:@"myurl1", nil];

NSURL *imageURL = [NSURL URLWithString:@"http://url/to/image.png"];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage *image = [UIImage imageWithData:imageData];
NSArray *imagesArray = [NSArray arrayWithObjects:image, nil];

[FBDialogs presentOSIntegratedShareDialogModallyFrom:self
                                                 session:nil
                                             initialText:@"My message for facebook"
                                                  images:imagesArray
                                                    urls:urlsArray
                                                 handler:^(FBOSIntegratedShareDialogResult result, NSError *error) {

                                                     NSLog(@"Result : %u", result);

                                                     if (error != nil) {
                                                         NSLog(@"Error : %@", [error localizedDescription]);
                                                     }
    }];