Reputation: 3391
I'm trying to post a message or share a photo in my fb using FacebookSDK. I already follow the steps on how to install it. I'm done applying the login tutorial, but the problem now is how to post a message or share it into my FB using my app. There are a lot of tutorial like this one. I think this is already old for FacebookSDK. Sorry If I'm so noob for this. I know this not the right page to post this, but I don't have any idea now. If you have a tutorial on how to post or share. Please give me link. If ever, can you provide steps for this.
I already try this, but It doesn't post or share.
UPdate
this is my code
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];
}
here's the code for my login. I think this is simple code
@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.
}
Upvotes: 0
Views: 3383
Reputation: 700
You did not set permissions, to set the permissions:
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");
}
}];
Also it is a good practice to check if user has granted the permission or not in your IBAction method:
- (IBAction)shareButton:(id)sender {
if ([[FBSDKAccessToken currentAccessToken] hasGranted:@"publish_actions"])
{
// code to share
}
}
Upvotes: 1