Facebook喜欢 - php代码 - 设置og:图像

问题描述 投票:2回答:2

我的网站上有facebook按钮。看起来像:

<span class="fblike" style="float:right;padding-top:5px;margin-left:8px;">
    <div id="fb-root"></div>
        <script>
            window.fbAsyncInit = function() 
            {
                FB.init({appId: 'Your ID#', status: true, cookie: true,xfbml: true});
            };
            (function() {
                var e = document.createElement('script'); e.async = true;
                e.src = document.location.protocol + '//connect.facebook.net/sk_SK/all.js';
                document.getElementById('fb-root').appendChild(e);
            }());
        </script>
        <fb:like layout="button_count" show_faces="false" width="64" action="like" font="arial" colorscheme="light" />
</span>

我的问题是,我无法设置og:我想要的图像:(无论我放置标签。它应该在标签中,但我的default.php文件中没有。我在joomla工作,这是我的一个组件。

php image facebook facebook-graph-api facebook-like
2个回答
1
投票

要在所有初始化后在FB墙上显示您选择的图像,您应该:

  1. 将HTML标记替换为 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://ogp.me/ns#" xmlns:fb="https://www.facebook.com/2008/fbml">
  2. 在你的头部添加og标签: <meta property="og:title" content="title of your page"/> <meta property="og:type" content="website"/> <meta property="og:url" content="url of your page"/> <meta property="og:image" content="path of image u want to display"/> <meta property="og:site_name" content="name of your site"/> <meta property="og:description" content="some brief description about your page "/> <meta property="fb:app_id" content="your fb app id"/>

在此之后,您可以使用此debugger tool检查从您的网站中删除的数据。

如果没有错误或警告,您都可以使用“喜欢”按钮。


0
投票

Open Graph元标记应该在head部分,并且您的HTML应该是正确的。首先,确保这一点。

使用this tool检查facebook如何解析您的网站。

© www.soinside.com 2019 - 2024. All rights reserved.