Wie zum senden der og:Title og:Image og:Description og:url-Infos von C# zu Facebook

Ich habe einen like-button in meine Seite. Klick auf den Button, ich bin versucht, senden Sie den folgenden tags Informationen in der 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" />

Folgende ist meine 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>

Folgende ist der erste Ansatz, um dynamisch zu behandeln, die 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);

}

Folgenden wird der zweite Ansatz, um dynamisch zu behandeln, die 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);

Schließlich ist es das rendering und die meta-tags wie unten..

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

Nun den moment, als ich Sie auf die Like button es sendet nur die url. und nicht sendet, die Description/Image/Title.

Ich bin mit dem link "http://developers.facebook.com/tools/debug". Er sagt, dass die Description/Image/Title fehlt.

Irgendwelche Ideen?

InformationsquelleAutor | 2012-06-08

Schreibe einen Kommentar