我试图使用FacebookSDK发布消息或在我的fb中分享照片。我已经按照如何安装它的步骤。我已经完成了应用登录教程,但现在的问题是如何使用我的应用程序发布消息或将其分享到我的FB中。有很多这样的教程one。我认为这对于FacebookSDK已经很老了。对不起如果我是这样的noob。我知道这不是发布此页面的正确页面,但我现在不知道。如果您有关于如何发布或分享的教程。请给我链接。如果有的话,你能为此提供一些步骤吗?
我已经尝试this了,但它没有发布或分享。
更新
这是我的代码
import "ShareController.h"
#import <FBSDKShareKit/FBSDKShareKit.h>
#import <FBSDKMessengerShareKit/FBSDKMessengerShareKit.h>
@implementation ShareController
- (void)viewDidLoad {
[super viewDidLoad];
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:@"https://developers.facebook.com"];
FBSDKShareButton *button = [[FBSDKShareButton alloc] init];
button.shareContent = content;
[self.view addSubview:button];
}
- (IBAction)shareButton:(id)sender {
UIImage * image = [UIImage imageNamed:@"sample.png"];
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = image;
photo.userGenerated = YES;
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
content.photos = @[photo];
FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
dialog.fromViewController = self;
dialog.shareContent= content;
dialog.mode = FBSDKShareDialogModeShareSheet;
[dialog show];
}
这是我登录的代码。我认为这是简单的代码
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
loginButton.center = self.view.center;
[self.view addSubview:loginButton];
// Do any additional setup after loading the view, typically from a nib.
}
答案 0 :(得分:1)
您未设置权限,以设置权限:
FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
loginButton.center = self.view.center;
[loginButton logInWithPublishPermissions: @[@"publish_actions"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
NSLog(@"Process error");
} else if (result.isCancelled) {
NSLog(@"Cancelled");
} else {
NSLog(@"Logged in");
}
}];
最好检查用户是否已在IBAction方法中授予权限:
- (IBAction)shareButton:(id)sender {
if ([[FBSDKAccessToken currentAccessToken] hasGranted:@"publish_actions"])
{
// code to share
}
}