Facebook 分享内容仅分享 URL iOS 9

Facebook share content only shares URL in iOS 9

FBSDKShareDialog 共享 FBSDKShareLinkContent 在 iOS 8 中工作正常,但无法在 [=] 上共享 imageURLcontentTitlecontentDescription 50=] 9 台设备。

该应用程序使用 iOS 9 SDK,Xcode 7,Facebook SDK 4.7.0 构建,Preparing Your Apps for iOS9 中提到的所有操作均已完成。该应用目前在 App Store 中不可用,Facebook 应用处于开发模式。

显示对话框的代码很常见 (Swift 2.0):

let content = FBSDKShareLinkContent()

content.contentURL = <URL to the app in the App Store>
content.imageURL = <valid image URL>
content.contentTitle = <some title>
content.contentDescription = <some descr>

let shareDialog = FBSDKShareDialog()
shareDialog.fromViewController = viewController
shareDialog.shareContent = content
shareDialog.delegate = self

if !shareDialog.canShow() {
    print("cannot show native share dialog")
}

shareDialog.show()

On iOS 9 Facebook SDK 呈现没有图像、标题和描述的原生对话框:

出现对话框时,当 FB 应用程序安装在 iOS 9 设备上时,出现错误,通过将相应的 URL 添加到 Info.plist 解决没有解决问题。只是不再出现的日志语句。

-canOpenURL: failed for URL: "fbapi20150629:/" - error: "This app is not allowed to query for scheme fbapi20150629"

这会导致空 post:

在 iOS 8 上,对话框是通过 FB 应用程序显示的,或者在未安装 FB 应用程序时打开 in-app Safari vc。

为了比较,相同的代码适用于 iOS 8 台设备:

更新:

虽然 solves the initial issue, it worth noting about

我遇到了同样的问题,我使用的解决方法是将共享对话框模式设置为使用本机应用程序。

我正在使用 Obj-C,但在 Swift 中应该几乎相同:

FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
dialog.fromViewController = viewController;
dialog.shareContent = content;
dialog.mode = FBSDKShareDialogModeNative; // if you don't set this before canShow call, canShow would always return YES
if (![dialog canShow]) {
    // fallback presentation when there is no FB app
    dialog.mode = FBSDKShareDialogModeFeedBrowser;
}
[dialog show];

在 iOS9 中,用户会看到应用程序切换对话框,但它工作正常。还有 FBSDKShareDialogModeWeb,它没有应用程序切换对话框,但也不显示图像。

默认是FBSDKShareDialogModeAutomatic,它选择了FBSDKShareDialogModeShareSheet,这就是你看到的。

更新:这是 iOS9 中可用对话模式的行为:

  • FBSDKShareDialogModeAutomatic:使用ShareSheet,这是OP案例
  • FBSDKShareDialogModeShareSheet:同上
  • FBSDKShareDialogModeNative:如果用户安装了 FB 应用程序,则有效,否则静默失败。显示应用程序切换对话框。
  • FBSDKShareDialogModeBrowser:无图分享
  • FBSDKShareDialogModeWeb:无图分享
  • FBSDKShareDialogModeFeedBrowser按预期工作
  • FBSDKShareDialogModeFeedWeb按预期工作

"Browser" 全屏打开 Safari,"Web" 打开 webview 对话框。

我会选择 iOS9 的最后两个选项和 iOS8 的自动。

删除错误消息: -canOpenURL: failed for URL: "fbapi20150629:/" - error: "This app is not allowed to query for scheme fbapi20150629",你可以在你项目的info.plist中的<key>LSApplicationQueriesSchemes</key>数组中添加如下行:

<string>fbapi20150629</string>

该问题的解决方案是将共享对话框模式设置为使用本机应用程序。在iOS9、swift 2.0

For first question: Facebook Share content can share url other than iTunes with content description. If iTunes url is shared it wont share our description.

Next: I was having the same issue, FB Share button clicking redirects me to browser and the workaround I'm using is to set the Share Dialog mode to use the native app.

This occurs consistently if the URL you are sharing is an iTunes App Store URL. Changing the URL to any other website solved the problem. https://developers.facebook.com/docs/sharing/ios"

Note: If your app share links to the iTunes or Google Play stores, we do not post any images or descriptions that you specify in the share. Instead we post some app information we scrape from the app store directly with the Webcrawler. This may not include images. To preview a link share to iTunes or Google Play, enter your URL into the URL Debugger."

  func shareFB(sender: AnyObject){

    let content : FBSDKShareLinkContent = FBSDKShareLinkContent()

    content.contentURL = NSURL(string: "//URL other then iTunes/AppStore")
    content.contentTitle = “MyApp”
    content.contentDescription = “//Desc“

    content.imageURL = NSURL(string:“//Image URL”)


    let dialog : FBSDKShareDialog = FBSDKShareDialog()
    dialog.mode = FBSDKShareDialogMode.Native
  // if you don't set this before canShow call, canShow would always return YES
    if !dialog.canShow() {
        // fallback presentation when there is no FB app
      dialog.mode = FBSDKShareDialogModeFeedBrowser
     }
    dialog.show()
 }

您应用中的 Facebook 分享对话框,包含标题、描述和图片:

  1. iOS:

dialog.mode = FBSDKShareDialogMode.ShareSheet //没试过

or
//Working for me:


let linkcontent: FBSDKShareLinkContent = FBSDKShareLinkContent()
        linkcontent.contentURL = videoURL
 //       linkcontent.contentDescription = videoDesc
 //       linkcontent.contentTitle = videoTitle
 //       linkcontent.imageURL = imageURL
        FBSDKShareDialog.showFromViewController(self, withContent: linkcontent, delegate: self)
  1. 网页实现:分享的link标题、描述和图片应该是url的回复,由Facebook自动带来。 例如:

元http-equiv="content-type"内容="text/html; charset=utf-8"> 标题>我的碎片 URL 标题 元内容='" + imageUrl + "' 属性='og:image'/>

如果您要共享的网站是您的网站管理员,最好的办法就是共享 contentURL。然后按照此处的信息将 Open Graph 标记添加到您的 HTML 文件:https://developers.facebook.com/docs/sharing/webmasters

Facebook 将从网页中抓取信息并从那里填充所有字段。为了确保值看起来正确,运行 调试器:

https://developers.facebook.com/tools/debug/

在该页面上,您实际上可以再次强制抓取,这将被缓存。

如果我们将 FBSDKShareLinkContent contentURL 设为空白,Facebook 标题将被共享。

例如:

content.contentURL = [[NSURL alloc] initWithString:@"http://"];
This works for me:-

FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:APP_STORE_LINK];
content.imageURL=[NSURL URLWithString:IMAGE_LINK];

FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
dialog.shareContent = content;
dialog.fromViewController = self;
dialog.mode = FBSDKShareDialogModeFeedBrowser;
[dialog show];

下面的代码在所有类型的情况下都对我很有帮助:

@IBAction func facebookTap() {
    let content = FBSDKShareLinkContent()
    content.contentTitle = imageTitle
    content.contentURL =  URL(string: "http://technokriti.com/")
    content.imageURL = URL(string: self.imageURL)
    content.contentDescription = imageDescription

    let dialog : FBSDKShareDialog = FBSDKShareDialog()
    dialog.fromViewController = self
    dialog.shareContent = content
    dialog.mode = FBSDKShareDialogMode.feedWeb
    dialog.show()
}

对于Swift >= 5.0,您可以按照下面的教程...

Facebook, Messenger - Photo, Video, Link sharing in iOS Swift.