gpt4 book ai didi

facebook - 通过 FB.api 函数将 .php 文件链接到 Facebook Graph 时遇到问题

转载 作者:行者123 更新时间:2023-12-02 21:33:35 24 4
gpt4 key购买 nike

我已经成功实现了 Facebook Recipe Box教程。现在我想进行一些修改,以便不再总是发布带有静态开放图标签的 HTML 文件,而是发布一个 .php 文件,该文件将允许我动态更改这些标签。我试图发布的 php 如下:

<?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 时,一切正常。谁能解释一下吗?

最佳答案

您必须对作为参数传递的 URL 进行编码(escape()):

之前

/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);
}
});

关于facebook - 通过 FB.api 函数将 .php 文件链接到 Facebook Graph 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8843460/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com