3

我已經成功地實現了Facebook Recipe Box教程鏈接一個PHP文件到Facebook的圖表。現在我想稍作修改,以便不要總是發佈帶有靜態開放圖形標籤的HTML文件,而是發佈一個.php文件,這將允許我動態更改這些標籤。我試圖發佈PHP如下:遇到問題通過FB.api功能

<?php 
function curPageURL() { 
$pageURL = 'http://'; 
if ($_SERVER["SERVER_PORT"] != "80") { 
    $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; 
} else { 
    $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; 
} 
    return $pageURL; 
    } 
    ?> 

    <html> 
    <head prefix="og: http://ogp.me/ns# wishlisteight: http://ogp.me/ns/fb/wishlisteight#"> 
      <meta property="fb:app_id"   content="366730473342905"> 
    <meta property="og:url"   content="<?php echo strip_tags(curPageURL());?>"> 
    <meta property="og:type"    content="carpenterben:nail"> 
    <meta property="og:title"    content="<?php echo strip_tags($_REQUEST['name']);?>"> 
     <meta property="og:image"    content="http://cdn2.digitaltrends.com/wp-content/uploads/2011/11/google_logo.jpg"> 
     <title>Product Name</title> 
    </head> 
    <body> 
    <div id="fb-root"></div> 
    <script src="http://connect.facebook.net/en_US/all.js"></script> 
    <script> 
    FB.init({ 
     appId:'366730473342905', 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="Stuffed Cookies" 
         src="http://www.thepropagator.com/facebook/RecipeBox/cookie.jpg" 
         width="550"/><br /> 
    </p>  
</body> 
</html> 

我用做後的代碼如下:

<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US"> 

    <head prefix="og: http://ogp.me/ns# carpenterben: http://ogp.me/ns/apps/carpenterben#"> 
    <meta property="fb:app_id" content="366730473342905" /> 
<meta property="og:type" content="carpenterben:nail" /> 
<meta property="og:title" content="Oreo Stuffed Cookies" /> 
<meta property="og:image" content="http://www.thepropagator.com/facebook/RecipeBox/cookie.jpg" /> 
<meta property="og:description" content="The Turducken of Cookies" /> 
<meta property="og:url" content="http://www.thepropagator.com/facebook/Carpenter/nail.php"> 

    <script type="text/javascript"> 
    function postCook() 
    { 
     FB.api('/me/carpenterben:hammer&nail=http://www.thepropagator.com/facebook/Carpenter/nail.php?name=great','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="http://connect.facebook.net/en_US/all.js"></script> 
    <script> 
    FB.init({ 
     appId:'366730473342905', 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="Oreo Stuffed Cookies" src="http://www.thepropagator.com/facebook/RecipeBox/cookie.jpg" width="550"/><br /> 
    </p> 

    <form> 
     <input type="button" value="Cook" onclick="postCook()" /> 
    </form> 

    <fb:activity actions="carpenterben:hammer"></fb:activity> 
</body> 

這將返回一個錯誤,但第二我改變我的文件擴展名爲HTML一切正常。任何人都可以解釋嗎?

回答

0

你必須進行編碼(轉義())要傳遞作爲參數的網址:

/me/carpenterben:hammer&nail=http://www.thepropagator.com/facebook/Carpenter/nail.php?name=great 

以前

/me/carpenterben:hammer&nail=http%3A//www.thepropagator.com/facebook/Carpenter/nail.php%3Fname%3Dgreat 

只是像做

function postCook() 
{ 
    url = escape('http://www.thepropagator.com/facebook/Carpenter/nail.php?name=great') 
    FB.api('/me/carpenterben:hammer&nail='+url,'post', function(response) { 
    if (!response || response.error) { 
     alert('Error occured'); 
     } else { 
     alert('Post was successful! Action ID: ' + response.id); 
     } 
});