iOS中的Facebook共享

iOS中的Facebook共享,ios,objective-c,iphone,facebook,facebook-graph-api,Ios,Objective C,Iphone,Facebook,Facebook Graph Api,我在我的应用程序中实现了Facebook共享 FBSDKShareLinkContent *content=[[FBSDKShareLinkContent alloc]init]; [content setContentDescription:theDescription]; [content setContentTitle:theTitle]; //[content setContentURL:[NSURL URLWithString:itemU

我在我的应用程序中实现了Facebook共享

FBSDKShareLinkContent *content=[[FBSDKShareLinkContent alloc]init];
        [content setContentDescription:theDescription];
        [content setContentTitle:theTitle];
        //[content setContentURL:[NSURL URLWithString:itemURL]];
       // content.contentURL = [NSURL URLWithString:@"http://developers.facebook.com"];
       [content setImageURL:[NSURL URLWithString:imageURL]];
    [FBSDKShareDialog showFromViewController:self withContent:content delegate:self];

但“共享”对话框显示为空。为什么它不显示/发布我设置的标题和描述?

共享视图的文本没有预先填充,因为Facebook不允许您这样做。当链接显示在Facebook上时,会使用内容描述和标题,这与共享措辞不同。

共享视图的文本不会预先填充,因为Facebook不允许您这样做。当链接显示在Facebook上时,会使用内容描述和标题,这与共享措辞不同。

试试看

FBSDKShareDialog *shareDialog = [[FBSDKShareDialog alloc] init];
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc]init];
[content setContentDescription:theDescription];
[content setContentTitle:theTitle];
[content setImageURL:[NSURL URLWithString:imageURL]];

[shareDialog setMode:FBSDKShareDialogModeAutomatic];
[shareDialog setShareContent:content];
[shareDialog setFromViewController:self];
[shareDialog show];
试试看

FBSDKShareDialog *shareDialog = [[FBSDKShareDialog alloc] init];
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc]init];
[content setContentDescription:theDescription];
[content setContentTitle:theTitle];
[content setImageURL:[NSURL URLWithString:imageURL]];

[shareDialog setMode:FBSDKShareDialogModeAutomatic];
[shareDialog setShareContent:content];
[shareDialog setFromViewController:self];
[shareDialog show];
你能试试这个(Objective-C)吗?在Swift中对我来说效果很好:

func shareLinks(title:String, imageUrl:String, contentUrl:String, vc:UIViewController){
        var fbcontent = FBSDKShareLinkContent()
        //Valid url that contains any content
        fbcontent.contentURL = NSURL(string: contentUrl)
        //Title of this post
        fbcontent.contentTitle = title
        //Image will be displayed in timeline with this post
        fbcontent.imageURL = NSURL(string: imageUrl)
        dialog.shareContent = fbcontent
        dialog.fromViewController = vc
        dialog.mode = FBSDKShareDialogMode.Automatic
        dialog.show()
    }
你能试试这个(Objective-C)吗?在Swift中对我来说效果很好:

func shareLinks(title:String, imageUrl:String, contentUrl:String, vc:UIViewController){
        var fbcontent = FBSDKShareLinkContent()
        //Valid url that contains any content
        fbcontent.contentURL = NSURL(string: contentUrl)
        //Title of this post
        fbcontent.contentTitle = title
        //Image will be displayed in timeline with this post
        fbcontent.imageURL = NSURL(string: imageUrl)
        dialog.shareContent = fbcontent
        dialog.fromViewController = vc
        dialog.mode = FBSDKShareDialogMode.Automatic
        dialog.show()
    }
如果你分享这个

[NSURL URLWithString:@"http://developers.facebook.com"];
共享对话框是否显示为空

若并没有——你们必须知道,你们共享的页面上必须有开放的图形信息

供分享图片使用

FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
  photo.image = image;
  photo.userGenerated = YES;
  photo.caption=@"Some text";
  FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
  content.photos = @[photo];
如果你分享这个

[NSURL URLWithString:@"http://developers.facebook.com"];
共享对话框是否显示为空

若并没有——你们必须知道,你们共享的页面上必须有开放的图形信息

供分享图片使用

FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
  photo.image = image;
  photo.userGenerated = YES;
  photo.caption=@"Some text";
  FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
  content.photos = @[photo];

您可以使用SLComposer作为FBSDK 4.12.0版本的备选方案

您可以使用SLComposer作为FBSDK 4.12.0版本的备选方案

Facebook链接共享的工作方式如下:

 FBSDKShareLinkContent *content =[[FBSDKShareLinkContent alloc] init];
 content.contentURL = [NSURL URLWithString:songUrl];
 content.imageURL = [NSURL URLWithString:artWorkURL];
 content.contentTitle= [NSString stringWithFormat: @"%@", trackName];
 content.contentDescription=[NSString stringWithFormat:@"Some text"];
 [FBSDKShareDialog showFromViewController:self withContent:content delegate:self];

对于FBSDK 4.12.0版本:

Facebook链接共享的工作方式如下:

 FBSDKShareLinkContent *content =[[FBSDKShareLinkContent alloc] init];
 content.contentURL = [NSURL URLWithString:songUrl];
 content.imageURL = [NSURL URLWithString:artWorkURL];
 content.contentTitle= [NSString stringWithFormat: @"%@", trackName];
 content.contentDescription=[NSString stringWithFormat:@"Some text"];
 [FBSDKShareDialog showFromViewController:self withContent:content delegate:self];


好的,谢谢你的回复,但是如何只发布文本为什么图像也不显示?如果显示链接,则标题和说明将从URL内容中添加,而不是从programmaticallyok中添加,谢谢您的回复,但如何仅发布文本?&为什么图像也不显示?如果显示链接,则标题和说明将从URL内容中添加,而不是从programmaticallywait中添加。。。我正在检查我是否已编辑,如果它仍然不工作,请将FBSDKShareDialogModeAutomatic模式更改为FBSDKShareDialogModeBrowser。实际上,我需要本机应用程序,因此我设置了
自动模式
,但不工作等待。。。我正在检查我是否已编辑如果仍不工作,请将FBSDKShareDialogModeAutomatic模式更改为FBSDKShareDialogModeBrowser。实际上,我想要本机应用程序,所以我设置了
自动模式
但不工作。另外,请不要添加内容URL并检查它不会工作。如果没有内容URL,请不要添加内容URL并检查它不会工作。如果没有内容URL,请不要添加内容URL并检查它不会工作。谢谢你的回答,但我没有链接来共享我只有文本和图像来共享我你共享图像试试这个FBSDKSharePhotouse photo.caption或content.caption它给我错误com.facebook.sdk:FBSDkerrodeveloperMessageKey=照片必须有UIImages我尝试设置图像URL设备上有图像吗?或者仅通过Url?谢谢您的回答,但我没有链接可共享我只有文本和图像可共享我您共享图像尝试此FBSDKSharePhotouse photo.caption或content.caption它给我错误com.facebook.sdk:FBSDkerrodDeveloperMessageKey=照片必须有UIImages我尝试设置图像Url设备上有图像吗?还是仅通过Url?