我很难在iOS应用中尝试使用FaceBookSDK。
在Xcode中,我创建了一个新项目,单视图应用程序(部署目标:7.1)。
首先,我只想要一个按钮,在点击时向Facebook发布内容。 与点击 HelloFacebookSample 应用中的“发布状态更新”按钮时发生的情况类似。 我从FacebookSDK(版本3.16.1)提供的 HelloFacebookSample 中复制了一些我认为需要的代码。
以下是我的应用中的代码:
#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
但是在运行时,没有任何内容发布,我总是收到这条消息:
Oops, Something Went Wrong
There was a problem posting your status. We’ve logged the error and will look into it.
我做错了什么?