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?