0

I am having a hard time trying to do something with FaceBookSDK in an iOS app.

In Xcode I created a New Project, Single View Application (Deployment target: 7.1).

For start, I just want to have a button that post something to Facebook when tapped. Similar to what happens when tapping the “Post Status Update” button in the HelloFacebookSample app. I copied some code I think is needed from HelloFacebookSample provided with the FacebookSDK (Version 3.16.1).

Here is the code in my app:

#import "ViewController.h"

@interface ViewController ()
{
    UIButton *fbButton;
}
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    fbButton=[[UIButton alloc] initWithFrame:CGRectMake(100.0, 150.0, 120.0, 50.0)];
    [fbButton setTitle:@"FB" forState:UIControlStateNormal];
    [fbButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    [fbButton.titleLabel setFont:[fbButton.titleLabel.font fontWithSize:58.0]];
    [fbButton addTarget:self action:@selector(fbButtonHandler) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:fbButton];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)fbButtonHandler
{
    NSLog(@"fbButtonHandler CALLED !!!!");
    NSURL *urlToShare = [NSURL URLWithString:@"http://developers.facebook.com/ios"];

    FBLinkShareParams *params = [[FBLinkShareParams alloc] initWithLink:urlToShare
                                                                   name:@"Hello Facebook"
                                                                caption:nil
                                                            description:@"The 'Hello Facebook' sample application showcases simple Facebook integration."
                                                                picture:nil];

    if (![FBDialogs canPresentShareDialogWithParams:params]) {
        NSLog(@"NO canPresentShareDialogWithParams !!!!");
        return;
    }

    FBAppCall *appCall = [FBDialogs presentShareDialogWithParams:params
                                                     clientState:nil
                                                         handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
                                                             if (error) {
                                                                 NSLog(@"Error: %@", error.description);
                                                             } else {
                                                                 NSLog(@"Success!");
                                                             }
                                                         }];
    if (!appCall)
        NSLog(@"NO appCall !!!!");
}


@end

But when running it, nothing is posted and I always get this message:

Oops, Something Went Wrong
There was a problem posting your status. We’ve logged the error and will look into it.

What did I do wrong?

Naga Mallesh Maddali
  • 1,005
  • 10
  • 19
Michel
  • 10,303
  • 17
  • 82
  • 179
  • This can help: http://stackoverflow.com/questions/24748202/ios-failure-to-post-on-facebook-no-errors-logged – Akshit Zaveri Jul 28 '14 at 04:05
  • I guess the problem is, with the session. I didn't see you have created/open a session anywhere. Try this thread step-by-step, configure facebook SDK and relevant stuff. This thread invites facebook friends. If this works, means you have configured things correctly: http://stackoverflow.com/questions/15495462/presentrequestsdialogmodallywithsession-does-not-work-but-gives-good-result/16654666#16654666 – NeverHopeless Jul 28 '14 at 04:31
  • Thanks I will take a look then. But where is this session created/open in the HelloFacebookSample app example? This may well be what I missed. – Michel Jul 28 '14 at 07:20
  • You don't need an open session (or any session at all) to use the share dialogs as offered by the SDK. You do need to add things like your app id and app name in your app's plist - see the prerequisites for https://developers.facebook.com/docs/ios/share – Ming Li Jul 28 '14 at 17:03
  • Yes I finally made it work by adding the app on the Facebook developer site. This is the part I was totally missing before. – Michel Jul 29 '14 at 02:27

0 Answers0