更新和:标题

问题描述 投票:0回答:1

我使用本教程https://developers.facebook.com/docs/opengraph/tutorial/制作我的第一个应用程序,但我想使用php变量为我的og:标题像这样“/>。这个php变量每次页面加载时都会不断变化,但是当我在facebook中发布我的动作时出现旧标题!这是代码:

      <?php
    $title = ' Hello world';
 // <---- This php variable is changing every time 
the page loads but the title is not being recognised

    ?>
    <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US"
    xmlns:fb="https://www.facebook.com/2008/fbml"> 
    <head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# fitnessgod: http://ogp.me/ns/fb/fitnessgod#">
    <meta property="og:locale" content="en_US" />
    <meta property="fb:app_id" content="My app Id" /> 
    <meta property="og:type" content="fitnessgod:news" /> 
    <meta property="og:url" content="https://www.fitness-god.com/share-facebook.php" /> 
    <meta property="og:title" content="<?php echo $title; ?>" /> 
    <meta property="og:description" content="let's do sport" /> 
    <meta property="og:image" content="https://www.fitness-god.com/images/sport dinamic.png" /> 

<script type="text/javascript">
    function postCook()
    {
    FB.api('/me/fitnessgod:share' + 
    '?news=https://www.fitness-god.com/share-facebook.php','post',
    function(response) {
    if (!response || response.error) {
    alert('Error occured');
    } else {
    alert('Post was successful! Action ID: ' + response.id);
    }
    });
    }
    </script>
    </head> 

<body> 

    <div id="fb-root"></div>

    <script src="https://connect.facebook.net/en_US/all.js"></script>

    <script>

    FB.init({ 

    appId:'My App id', cookie:true, 

    status:true, xfbml:true, oauth:true

    });

    </script>

<fb:add-to-timeline></fb:add-to-timeline>

<h3>

    <font size="30" face="verdana" color="grey">

    Stuffed Cookies

    </font> 

    </h3> 

    <p>

    <img title="Sports News" 

    src="https://www.fitness-god.com/images/sport dinamic.png" 

    width="550"/><br />

    </p> 

 <form>

    <input type="button" value="Share news" onClick="postCook()" /> 

    </form>
    <fb:activity actions="fitnessgod:share"></fb:activity>
    </body> 

    </html>
facebook facebook-like facebook-opengraph
1个回答
0
投票

您需要更正元标记定义。使用属性名称,而不是属性:

例如:

<meta name="og:title" content="<?php echo $title; ?>" />

您可以使用调试器来测试代码:

http://developers.facebook.com/tools/debug

另请注意,单击共享时,可能会缓存页面内容。但是,调试器始终获取最新内容。

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