我的页面上有一个赞按钮。单击按钮时,我试图在 facebook 中发送以下标签信息...
<meta property="og:title" content="Title" />
<meta property="og:description" content="Description" />
<meta property="og:url" content="url info" />
<meta property="og:image" content="image url" />
以下是我的点赞按钮框架
<iframe frameborder="0" scrolling="no" allowtransparency="true"
style="border: none; overflow: hidden; width: 260px; height: 35px;"
src="http://www.facebook.com/plugins/like.php?
href=http://localhost:49334/WebForm1.aspx&send=false&
layout=button_count&width=100&show_faces=false&
action=like&colorscheme=light&font=arial&height=35">
</iframe>
下面是动态处理元标签的第一种方法。
var fbTitleTag = new MetaTag
{
AgentPageURL = "/",
MetaTagName = "og:title",
UserSiteName = CurrentAgent.UserSiteName,
MetaTagContent = Request.Cookies.Get("MasterTitle").Value
};
var fbDesc = new MetaTag
{
AgentPageURL = "/",
MetaTagName = "og:description",
UserSiteName = CurrentAgent.UserSiteName,
MetaTagContent = Request.Cookies.Get("MasterDescription").Value
};
var fbUrl = new MetaTag
{
AgentPageURL = "/",
MetaTagName = "og:url",
UserSiteName = CurrentAgent.UserSiteName,
MetaTagContent = Request.Cookies.Get("MasterURL").Value
};
var fbImage = new MetaTag
{
AgentPageURL = "/",
MetaTagName = "og:image",
UserSiteName = CurrentAgent.UserSiteName,
MetaTagContent = Request.Cookies.Get("MasterImage").Value
};
var tags = new MetaTagCollection { fbTitleTag, fbDesc, fbUrl, fbImage };
Literal ltMetaTags = null;
ltMetaTags = (Literal)this.Master.FindControl("ltMetaTags");
MetaTags(tags, "wsws", "/", ltMetaTags, true);
public static void MetaTags(MetaTagCollection MetaTags, string name, string strRawURL, Literal ltlMetaHolders, bool isProp)
{
// ltlMetaHolders.Text = "";
foreach (AgentMetaTag oAgentMetaTag in agentMetaTags)
{
if (string.Compare(strRawURL, oAgentMetaTag.AgentPageURL, true) == 0)
{
if (oAgentMetaTag.MetaTagName.ToLower().Trim() != "footer" && oAgentMetaTag.MetaTagName.ToLower().Trim() != "title")
{
if (oAgentMetaTag.MetaTagName.ToLower().Trim() == "fbtitle")
oAgentMetaTag.MetaTagName = "title";
RenderMetaTagByContentName(ltlMetaHolders, oAgentMetaTag.MetaTagName, oAgentMetaTag.MetaTagContent, isProp);
}
}
}
}
public static void RenderMetaTagByContentName(Literal ltlMetaHolder, string contentName, string content, bool isProp)
{
var metaTagFromat = isProp ? "<meta property=\"{0}\" content=\"{1}\" />" : "<meta name=\"{0}\" content=\"{1}\" /> ";
ltlMetaHolder.Text += string.Format(metaTagFromat, contentName, content);
}
下面是动态处理元标签的第二种方法。
HtmlMeta tag = new HtmlMeta();
tag.Attributes.Add("property", "og:title");
tag.Content = "Title";
Page.Header.Controls.Add(tag);
HtmlMeta tag1 = new HtmlMeta();
tag1.Attributes.Add("property", "og:description");
tag1.Content = "Desc";
Page.Header.Controls.Add(tag1);
HtmlMeta tagurl = new HtmlMeta();
tagurl.Attributes.Add("property", "og:url");
tagurl.Content = "URL info";
Page.Header.Controls.Add(tagurl);
HtmlMeta tagimg = new HtmlMeta();
tagimg.Attributes.Add("property", "og:img");
tagimg.Content = "Image URL";
Page.Header.Controls.Add(tagimg);
最后它呈现如下元标记..
<meta property="og:title" content="Title" />
<meta property="og:description" content="Description" />
<meta property="og:url" content="url info" />
<meta property="og:image" content="image url" />
现在,当我点击 Like 按钮
时,它只会发送 url。并且不发送 Description/Image/Title
。
我正在使用链接“http://developers.facebook.com/tools/debug”。它表示缺少 Description/Image/Title
。
有什么想法吗?
最佳答案
您不会将元数据发送到 Facebook,Facebook 在加载页面时会从页面的 HTML 中检索元数据。尝试使用以下工具查看您的网址:
http://developers.facebook.com/tools/debug/og/echo?q=<your URL here>
它将向您显示 Facebook 看到的内容(这是您现在使用的调试工具底部的“已抓取的 URL”链接)。
如果它不包含元数据标签,则 Facebook 看不到它们,也不会将元数据添加到其 Open Graph 对象中。如果是这种情况,那么您可能没有将元数据正确添加到 HTML。
关于c# - 如何发送og :Title og:Image og:Description og:url info from C# to Facebook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10946177/