我使用我的網站上的Facebook像按鈕,以便用戶可以喜歡一個體育比賽的預測。Facebook的喜歡按鈕創建一個新的頁面,不顯示正確的og:標題
我已經爲類似按鈕下面的代碼:
<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" />
自從我使用這個網頁上有關我的應用程序自定義操作爲好。當用戶對任何遊戲進行預測時,他們的預測將發佈在他們的時間線上。
如果我的網站的用戶進行了遊戲的預測發現here,然後提交表單的時候,下面的代碼會被執行:
$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_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中的參數設置爲「預測」和正確的開放圖形標籤顯示,在點擊類似按鈕,會創建一個新頁面並顯示錯誤的og:title。
任何意見/建議?
感謝,
蘭斯
是的,勝利是由FB批准運行的馬車URL。 – Lance
你如何獲得價值$ tab? –
$ tab = $ _GET ['tab']; – Lance