从C#的URL信息向Facebook:如何发送OG:标题OG:图片OG:说明OG [英] How to send the og:Title og:Image og:Description og:url info from C# to Facebook

查看:267
本文介绍了从C#的URL信息向Facebook:如何发送OG:标题OG:图片OG:说明OG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网页就像一个按钮。单击按钮时,我想寄于Facebook的下列标记的信息...

 <财产元=OG:标题CONTENT =标题/>
<财产元=OG:说明内容=说明/>
<财产元=OG:URLCONTENT =网址信息/>
<财产元=OG:形象CONTENT =图片URL/>

以下是我的Like按钮帧

 < IFRAME FRAMEBORDER =0SCROLLING =NOALLOWTRANSPARENCY =真
  风格=边界:无;溢出:隐藏; WIDTH:260px;高度:35px;
  SRC =htt​​p://www.facebook.com/plugins/like.php?
  HREF = HTTP://本地主机:49334 / WebForm1.aspx的&放大器;放大器;发送= FALSE&放大器;放大器;
  布局= button_count&放大器;放大器; WIDTH = 100&放大器;放大器; show_faces = FALSE&放大器;放大器;
  行动=喜欢和放大器;放大器;色彩方案=光&放大器;放大器; FONT =宋体和放大器;放大器; HEIGHT = 35>
< / IFRAME>

以下是第一条途径动态处理的Meta标签。

  VAR fbTitleTag =新的元标记
{
    AgentPageURL =/,
    MetaTagName =OG:称号,
    UserSiteName = CurrentAgent.UserSiteName,
    MetaTagContent = Request.Cookies.Get(MasterTitle)。价值
};VAR fbDesc =新的元标记
{
    AgentPageURL =/,
    MetaTagName =OG:描述,
    UserSiteName = CurrentAgent.UserSiteName,
    MetaTagContent = Request.Cookies.Get(MasterDescription)。价值
};
VAR fbUrl =新的元标记
{
    AgentPageURL =/,
    MetaTagName =OG:URL,
    UserSiteName = CurrentAgent.UserSiteName,
    MetaTagContent = Request.Cookies.Get(MasterURL)。价值
};VAR fbImage =新的元标记
{
    AgentPageURL =/,
    MetaTagName =OG:形象,
    UserSiteName = CurrentAgent.UserSiteName,
    MetaTagContent = Request.Cookies.Get(MASTERIMAGE)。价值
};VAR标签=新MetaTagCollection {fbTitleTag,fbDesc,fbUrl,fbImage};文字ltMetaTags = NULL;
ltMetaTags =(文字)this.Master.FindControl(ltMetaTags);元标记(标记WSWS,/,ltMetaTags,真正的);公共静态无效的元标记(MetaTagCollection元标记,字符串名称,字符串strRawURL,立即ltlMetaHolders,布尔isProp)
{
    // ltlMetaHolders.Text =;    的foreach(AgentMetaTag oAgentMetaTag在agentMetaTags)
    {
        如果(的String.Compare(strRawURL,oAgentMetaTag.AgentPageURL,真)== 0)
        {
            如果(oAgentMetaTag.MetaTagName.ToLower()修剪()=页脚&放大器;!&安培;!oAgentMetaTag.MetaTagName.ToLower()修剪()=题)
            {
                如果(oAgentMetaTag.MetaTagName.ToLower()。修剪()==fbtitle)
                    oAgentMetaTag.MetaTagName =称号;                RenderMetaTagByContentName(ltlMetaHolders,oAgentMetaTag.MetaTagName,oAgentMetaTag.MetaTagContent,isProp);
            }
        }
    }
}公共静态无效RenderMetaTagByContentName(文字ltlMetaHolder,字符串内容名,字符串内容,布尔isProp)
{
    VAR metaTagFromat = isProp? <财产元= \\{0} \\的内容= \\{1} \\/>中:< META NAME = \\{0} \\的内容= \\{1} \\/>中;    ltlMetaHolder.Text + =的String.Format(metaTagFromat,内容名,内容);}

以下是第二种方法来动态处理的Meta标签。

  HtmlMeta标签=新HtmlMeta();
tag.Attributes.Add(财产,OG:标题);
tag.Content =标题;
Page.Header.Controls.Add(标签);HtmlMeta标记1 =新HtmlMeta();
tag1.Attributes.Add(财产,OG:说明);
tag1.Content =说明;
Page.Header.Controls.Add(TAG1);HtmlMeta tagurl =新HtmlMeta();
tagurl.Attributes.Add(财产,OG:URL);
tagurl.Content =网址信息;
Page.Header.Controls.Add(tagurl);HtmlMeta tagimg =新HtmlMeta();
tagimg.Attributes.Add(财产,OG:IMG);
tagimg.Content =图片网址;
Page.Header.Controls.Add(tagimg);

最后它被渲染的meta标签如下..

 <财产元=OG:标题CONTENT =标题/>
<财产元=OG:说明内容=说明/>
<财产元=OG:URLCONTENT =网址信息/>
<财产元=OG:形象CONTENT =图片URL/>


  


现在的那一刻我点击 Like按钮它只发送的网址。而不是发送说明/图像/标题

我使用链接http://developers.facebook.com/tool​​s/debug。它说,在说明/图像/标题缺失。

任何想法?


解决方案

您没有元数据发送给Facebook,当加载页面的Facebook检索页面的HTML的元数据。尝试使用以下工具查看网址:

  http://developers.facebook.com/tool​​s/debug/og/echo?q=<your URL这里&GT;

它会告诉你的Facebook看到的东西(它的'刮URL在那你现在使用的调试工具的底部链接)。

如果它不包含元数据标签,那么Facebook并没有看到他们,也不会在元数据添加到它的Open Graph对象。如果是这样的话,那么你可能无法正确​​添加元数据的HTML。

I have a like button in my page. On clicking the Button, I am trying to send the following tags information in the 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" />

Following is my Like Button Frame

<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&amp;send=false&amp;
  layout=button_count&amp;width=100&amp;show_faces=false&amp;
  action=like&amp;colorscheme=light&amp;font=arial&amp;height=35">
</iframe>

Following is the first Approach to dynamically handle the Meta Tags.

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);

}

Following is the second Approach to dynamically handle the Meta Tags.

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);

Finally it is rendering the meta tags as below..

<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" />

Now the moment i click the Like button it only sends the url. and not sending the Description/Image/Title.

I am using the link "http://developers.facebook.com/tools/debug". It says that the Description/Image/Title is missing.

Any Ideas?

解决方案

You don't send the metadata to Facebook, Facebook retrieves the metadata from the page's HTML when it loads the page. Try viewing your URL with the following tool:

http://developers.facebook.com/tools/debug/og/echo?q=<your URL here>

It will show you what Facebook sees (it's the 'Scraped URL' link at the bottom of the debug tool that you're using now).

If it does not include the metadata tags then Facebook does not see them and it won't add the metadata to its Open Graph object. If that's the case then you might not be adding the metadata properly to the HTML.

这篇关于从C#的URL信息向Facebook:如何发送OG:标题OG:图片OG:说明OG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆