sharepoint - 将 Facebook 开放图谱协议(protocol)元标签添加到共享点

标签 sharepoint facebook-like

当我在我们的网站 (www.potatopro.com) 上点赞一篇带有 Facebook 点赞和 Facebook 分享按钮的文章时,会获取错误的网站数据。 要么您无法更改图片,要么在其他情况下 Facebook 会获取导航而不是内容。

据我了解,我必须在我们的网站上实现 Facebook 的开放图协议(protocol)元标记。但是对于基于共享点的网站我该如何做到这一点?请指教!

最佳答案

您可以将 Web 部件添加到页面正在使用的页面布局中。在 Web 部件中,您添加一个函数,用于查找页面上的标题、内容和图像,并将元标记写入页面正在使用的母版页。这是该函数的示例...

protected override void Render(HtmlTextWriter writer)
    {
        if (SPContext.Current != null && SPContext.Current.ListItem != null)
        {
            SPListItem item = SPContext.Current.ListItem;
            var title = item["Title"];
            if (title != null)
            {
                writer.WriteBeginTag("meta");
                writer.WriteAttribute("property", "og:title");
                writer.WriteAttribute("content", title.ToString());
                writer.WriteEndTag("meta");
            }
            var pageContent = item["PublishingPageContent"];
            if (pageContent != null)
            {
                string strippedPageContent = Regex.Replace(pageContent.ToString(), @"<(.|\n)*?>", string.Empty);
                    writer.WriteBeginTag("meta");
            writer.WriteAttribute("property", "og:description");
            writer.WriteAttribute("content", strippedPageContent);
            writer.WriteEndTag("meta");
            }

            var pageImage = item["PublishingPageImage"];
            if (pageImage != null)
            {
                ImageFieldValue pageImageValue = pageImage as ImageFieldValue;
                if (pageImageValue != null)
                {
                    var url = pageImageValue.ImageUrl;
                    writer.WriteBeginTag("meta");
                    writer.WriteAttribute("property", "og:image");
                    writer.WriteAttribute("content", url);
                    writer.WriteEndTag("meta");
                }
            }

        }
    }

关于sharepoint - 将 Facebook 开放图谱协议(protocol)元标签添加到共享点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5721746/

相关文章:

c# - 读取 SharePoint 2010 列表时出现“项目不存在”错误

c# - 如何在 Sharepoint 2007 Web 部件中托管 Silverlight 应用程序

facebook - Unlikes 因 2013 年 2 月的重大更改而失败

sharepoint - 功能激活

Sharepoint XSL 数据 View 查询字符串过滤

javascript - 如何在javascript中转换日期列值,以及如何增加此日期变量?

iphone - Facebook 非 friend 不能喜欢来自 ios 应用程序的公开帖子

html - Facebook Like 按钮在某个网站上不起作用?

html - Facebook 页面嵌入的 iframe 不填充容器宽度

jquery - 使用 JQuery 更改 Facebook 元标记内容属性