简体   繁体   English

无法使用Facebook分享链接内容在URL中添加描述和标题

[英]Can't add description and title to url using Facebook share link content

I try add description and title for share link content . 我尝试为共享链接内容添加描述和标题。 I am using pod 'FacebookShare' (because when i using FBSDKShareKit, description and title are deprecated) 我正在使用pod'FacebookShare'(因为当我使用FBSDKShareKit时,不赞成使用描述和标题)

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

This my code with 'FacebookShare' : 这是我的代码与“ FacebookShare”:

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

But i can see description and title only when i using : shareDialog.mode = .native In all other cases( .shareSheet, .Web, .Browser, .FeedWeb, .FeedBrowser) they don't added. 但只有在使用以下命令时,我才能看到说明和标题:shareDialog.mode = .native在所有其他情况下(.shareSheet,.Web,.Browser,.FeedWeb,.FeedBrowser),它们没有添加。 I am not want use .native mode because not everyone has native Facebook app. 我不想使用.native模式,因为不是每个人都有本机Facebook应用程序。 Is there any solution for my case? 我的案子有什么解决办法吗?

****UPDATE:**** ****更新:****

set up the proper meta tags on the site (which is i sharing url) itself for title, description and image values and for other variables. 在网站本身(我共享网址)上设置适当的元标记,以用于标题,描述和图像值以及其他变量。

The methods that allow attaching a link to posts now retrieve the image, the title and the description from proprietary meta tags and not from the code itself. 现在,允许将链接附加到帖子的方法现在从专有元标记而不是代码本身中检索图像,标题和说明。 Simply remove the lines to get rid of the warnings and set up the proper tags on the site itself. 只需删除行以消除警告,然后在网站本身上设置适当的标签。

See the exact deprecation changelog here: 在此处查看确切的弃用变更日志:

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

I had the same issue - title, description and imageUrl are deprecated and readonly in the latest Facebook SDK version. 我遇到了同样的问题-在最新的Facebook SDK版本中,标题,说明和imageUrl已弃用,并且为只读。 I just downloaded an old one from April 2017 and it's working as expected. 我刚刚从2017年4月下载了一个旧版本,它按预期运行。

You should update your myContent and shareDialog parts like this: 您应该像这样更新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)

You can also import and use Social library for creating Facebook share box. 您也可以导入和使用Social库来创建Facebook共享框。 And control your share results with Facebook share delegate functions. 并使用Facebook分享代表功能控制您的分享结果。 Like this way: 像这样:

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

Note: Try it with your device. 注意:在您的设备上尝试一下。 It doesn't work on simulator. 在模拟器上不起作用。 And be sure that the Facebook App is installed your device. 并确保已在您的设备上安装了Facebook App。

var content = LinkShareContent.init(url: URL.init(string: url)!) 

content.quote = "your content here"

Note in latest update description and title is deprecated so please use this instead that . 请注意,最新更新说明中的注释和标题已弃用,因此请使用代替。 don't forgot to import FacebookShare . 不要忘记导入FacebookShare。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM