我在我的网站上使用 facebook like 按钮,以便用户可以喜欢体育比赛的预测。
我有以下类似按钮的代码:
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=123456789";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<fb:like href="http://www.sportannica.com/games/mlb/1880/predictions/113" show_faces="false" data-send="true" font="verdana" layout="button_count"></fb:like>
在文件的开头,我有以下内容:
<meta property="og:title" content="Lance Newman's prediction for the Red Sox @ Yankees game on Friday, August 17" />
<meta property="og:description" content="Lance Newman predicted the Yankees to beat the Red Sox (6 to 4) on Friday, August 17 on Sportannica" />
<meta property="og:image" content="http://www.sportannica.com/img/team_icons/New York Yankees/1947.png" />
<meta property="og:site_name" content="Sportannica" />
<meta property="fb:app_id" content="123456789" />
<meta property="og:url" content='http://www.sportannica.com/games/mlb/1880/predictions/113' />
<meta property="og:restrictions:age" content="13+"/>
<meta property="og:determiner" content="auto" />
有人告诉我,点赞按钮触发创建新页面的原因是由于头部有一个 og:type 元标记。我曾经在文档的开头也有以下内容
<meta property="og:type" content="sportannica:victory" />
因为我确实使用此页面来为我的应用程序进行自定义操作。当用户对任何游戏进行预测时,他们的预测会发布在他们的时间线上。
如果我网站的用户对此处找到的游戏进行了预测,那么在提交表单时,将执行以下代码:
$queries = array(
array("method" => "POST", "relative_url" => "/me/sportannica:predict?victory=http://www.sportannica.com/games/".$league."/".$game."/predictions_post/".$_SESSION['id']."")
);
try
{
$postResponseA = $facebook->api('?batch='.json_encode($queries), 'POST');
} catch (FacebookApiException $e)
{
// echo 'AF error: '.$e.'';
}
注意在上面的例子中,参数不是等于“predictions”,而是“predictions_post”。
文档的打开图形标签中的内容取决于 url 中的参数设置为“predictions_post”还是“predictions”。
在我的文档的开头,我有以下 php 代码:
<meta property="og:title" content="
<?php
if($tab == "predictions_post")
{
echo "".$winner_short." victory";
} elseif($tab == "predictions")
{
if($gram == 1)
{
echo "".$first_name." ".$last_name."'s prediction for the ".$away_team_short." @ ".$home_team_short." game on ".$game_date."";
} else
{
echo "Predictions for ".$away_team_short." @ ".$home_team_short." on ".$game_date."";
}
}
?>
" />
<meta property="og:description" content="
<?php
if($tab == "predictions_post")
{
echo "".$first_name." ".$last_name." predicted the ".$winner_short." to beat the ".$loser_short." (".$win_score." to ".$lose_score.") on ".$game_date." on Sportannica";
} elseif($tab == "predictions")
{
if($gram == 1)
{
echo "".$first_name." ".$last_name." predicted the ".$winner_short." to beat the ".$loser_short." (".$win_score." to ".$lose_score.") on ".$game_date." on Sportannica";
} else
{
echo "Predictions for ".$away_team_short." @ ".$home_team_short." ".$game_date."";
}
}
?>
" />
<?php
if($tab == "predictions_post")
{
?>
<meta property="og:type" content="sportannica:victory" />
<?php
}
?>
但是,即使 URL 中的参数设置为“predictions”并显示正确的打开图形标签,在单击类似按钮时,也会创建一个新页面并显示错误的 og:title。
有什么想法/建议吗?
谢谢,
槊