gpt4 book ai didi

ios - 如何在 Facebook iOS SDK 中发布或分享?

转载 作者:行者123 更新时间:2023-11-29 01:13:31 26 4
gpt4 key购买 nike

我正在尝试使用 FacebookSDK 在我的 Facebook 中发布消息或分享照片。我已经按照如何安装它的步骤进行操作。我已经完成了登录教程的应用,但现在的问题是如何使用我的应用程序发布消息或将其分享到我的 FB 中。像这样的教程还有很多one .我认为这对于 FacebookSDK 来说已经很旧了。抱歉,如果我对此很菜鸟。我知道这不是发布此内容的正确页面,但我现在不知道。如果您有有关如何发布或分享的教程。请给我链接。如果有的话,您能否提供相关步骤。

我已经尝试过 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.
}

最佳答案

你没有设置权限,要设置权限:

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
}
}

These frameworks should be included

关于ios - 如何在 Facebook iOS SDK 中发布或分享?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35497325/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com