Facebook帖子带参数

时间:2013-03-13 06:34:17

标签: php facebook facebook-graph-api

我需要制作带有参数的Facebook帖子。我用过这里的解决方案: Generating Facebook Open Graph meta tags dynamically和此处:Dynamic Facebook og Meta Tags in Wordpress PHP

最终工作代码:

<?php

$params = array();
if(count($_GET) > 0) {
    $params = $_GET;
} else {
    $params = $_POST;
}
// defaults
if($params['title'] == "") $params['title'] = "default_title";
if($params['score'] == "") $params['score'] = "1234567";

?>

<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# pathoflight: http://ogp.me/ns/fb/pathoflight#">
  <meta property="fb:app_id"         content="MY_APP_ID" /> 
  <meta property="og:type"           content="pathoflight:level" /> 
  <meta property="og:url"            content="<?php echo 'https://path-of-light.herokuapp.com'.$_SERVER['REQUEST_URI']; ?>"/>
  <meta property="og:image"          content="https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png" /> 
  <meta property="og:title"          content="<?php echo $params['title']; ?>" /> 
  <meta property="pathoflight:score" content="<?php echo $params['score']; ?>" />
</head>

它在浏览器和Facebook调试器中运行良好,但我通过Facebook API Explorer发布的帖子总是会导致titlescore的默认值。如何告诉Facebook阅读真实的参数?

1 个答案:

答案 0 :(得分:0)

问题还在于,如果您发布这样的帖子,Facebook API Explorer会跳过参数

me/pathoflight:complete?level=https://path-of-light.herokuapp.com/level_new.php?title=my_title&score=223322

这种方法有效:

me/pathoflight:complete
Add a field
level     https://path-of-light.herokuapp.com/level_new.php?title=my_title&score=223322