无法使用Facebook共享链接内容为网址添加说明和标题

问题描述:

我尝试为共享链接内容添加说明和标题。我使用的吊舱“Facebook分享”(因为当我使用FBSDKShareKit,说明和标题不建议使用)无法使用Facebook共享链接内容为网址添加说明和标题

https://i.stack.imgur.com/9p9lp.jpg

这是我的代码“Facebook分享”:

 do{ 
      var myContent: LinkShareContent = LinkShareContent(url: NSURL(string:contentUrl!) as! URL) 
      myContent.description = "Some description" 
      myContent.title = "Hello" 

      let shareDialog = ShareDialog(content: myContent) 
      shareDialog.mode = .shareSheet 
      shareDialog.presentingViewController = self 
      shareDialog.failsOnInvalidData = true 
      shareDialog.completion = { result in 
       // Handle share results 
      } 
       try shareDialog.show() 
      } catch { 
       print("Error: \(error)") 
     } 

但我可以看到说明和标题仅当我使用时: shareDialog.mode = .native 在所有其他情况下(.shareSheet,.Web,.Browser,.FeedWeb,.FeedBrowser)它们不会被添加。我不想使用.native模式,因为不是每个人都有原生Facebook应用程序。 我的情况是否有解决方案?

**** UPDATE:****

建立适当的meta标签的网站(这是我分享的网址)本身标题,描述和图像值以及其他变量上。

应当更新myContentshareDialog部分是这样的:

 let myContent:FBSDKShareLinkContent = FBSDKShareLinkContent() 
     myContent.contentTitle = "Hello" 
     myContent.contentDescription = "Test message" 
     myContent.contentURL = (URL(string: "https://developers.facebook.com")) 

     let shareDialog = FBSDKShareDialog() 
     shareDialog.mode = .shareSheet 
     FBSDKShareDialog.show(from: self, with: myContent, delegate: nil) 

您也可以导入和使用Social库创建Facebook分享框。并通过Facebook共享委托功能控制您的分享结果。像这样:

import FBSDKShareKit 
import Social 

class YourViewController: UIViewController, FBSDKSharingDelegate { 
    func facebookShareButtonClicked() { 
     let vc = SLComposeViewController(forServiceType:SLServiceTypeFacebook) 
     vc?.add(UIImage(named: "YourImageName")) 
     vc?.add(URL(string: "https://developers.facebook.com")) //Your custom URL 
     vc?.setInitialText("Your sample share message...") 
     self.present(vc!, animated: true, completion: nil) 
    } 

//Facebook share delegate functions: 
    func sharer(_ sharer: FBSDKSharing!, didCompleteWithResults results: [AnyHashable : Any]!) { 
     print("Success") 
    } 

    func sharer(_ sharer: FBSDKSharing!, didFailWithError error: Error!) { 
     print("didFailWithError: ", error) 
    } 

    func sharerDidCancel(_ sharer: FBSDKSharing!) { 
     print("Sharer cancelled") 
    } 
} 

注意:尝试用您的设备。它在模拟器上不起作用。并确保Facebook应用程序已安装您的设备。

+0

我试过使用社会图书馆。它也不帮助我。共享是工作,但不添加初始文本。我正在使用设备。 Xcode 8.2.1,Swift 3.0。可能我必须使用.native模式。 – DmitriyYefremov

+0

我已经更新了我的答案。我用你的方法试了一下。你可以再次尝试使用我的答案中最重要的代码吗? – kkakkurt

+2

我试过了。方法myContent.contentTitle,myContent.contentDescription从Graph API 2.9中弃用。所以我认为这些方法不被使用。而Facebook从url的元描述中获得这些字段。 – DmitriyYefremov

允许将链接附加到帖子的方法现在从专有元标记中检索图像,标题和描述,而不是从代码本身检索。只需删除线条以摆脱警告,并在网站上设置适当的标签。

看到确切的折旧更新日志的位置:

https://developers.facebook.com/docs/apps/changelog#v2_9_deprecations

我有同样的问题 - 标题,描述和imageUrl在最新的Facebook SDK版本中被弃用和只读。我从2017年4月刚刚下载了一个旧的,并且按预期工作。