开发者

Facebook Like Meta Tags not showing correct image [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

How does Facebook Sharer select Images?

I'm using javascript to set the metatags for og: values and the FB Debugger is telling me that I need to explicitly set the meta tags for URL, Title and Image. I am seeing the metatags show up correctly in Firebug - they are there, but FB and the Like button aren't seeing them for some reason. Here's the JS:

function setMT(metaName, name, value) {
var t = 'meta['+metaName+'='+name+']';
var mt = $(t);
if (mt.length === 0) {
    t = '<meta '+metaName+'="'+name+'" />';
    mt = $(t).prependTo('head');
}
mt.attr('content', value);
}

and in the jQuery document ready I set the meta tags

setMT('property', 'og:title', 'PAGE_TITLE');
setMT('property', 'og:url', 'CURRENT_URL');
setMT('property', 'og:image', 'IMAGE_URL');

etc.开发者_运维问答

Anybody know if FB doesn't like my method? I can't set hard values for these meta tags, they are dynamically generated for on an e-commerce platform so I need to create the VARS in the template and use jQuery to pass them to the page content where I create the meta tags and prepend them to the HEAD of the document. Scratching my head a little on this one.


Javascript is only working in the user's browser. Facebook open graph crawler (and debugger based on it) call your page server to server and don't interpret any javascript. Therefore they don't see your tags. You should set them dynamically using any server-side language like php or asp.net, etc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜