当我在我们的网站 (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/