【发布时间】:2012-03-01 04:21:34
【问题描述】:
过去八个小时左右,我一直在不知疲倦地工作,试图以一种方式格式化我的 Wordpress 博客,这意味着用户可以通过使用文章的打开图表设置单击按钮并将文章发布到股票行情上.
我一直在使用here找到的教程。
很遗憾,我无法完成它,因为每次单击我创建的“发布”按钮时,都会弹出一条错误消息。
当使用 Facebook 的调试器时,我没有发现任何问题,并且所有必要的标签都已到位(我有一个插件可以为我做这件事,非常完美)。
以下是我对 header.php 文件所做的更改以适应教程:
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US"
xmlns:fb="https://www.facebook.com/2008/fbml">
在</head>之前添加以下内容:
<script type="text/javascript">
function postArticle()
{
FB.api(
'/me/[NAMESPACE]:read?Article=<?php get_permalink() ?>',
'post',
function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Successful! Action ID: ' + response.id);
}
});
}
</script>
清楚地放置了一个请求权限的登录按钮:
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '[APPLICATION ID]', // App ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
<fb:login-button perms="email,publish_actions,user_actions.news">
Login with Facebook
</fb:login-button>
最后将以下内容放在页面上我希望按钮出现的位置:
<fb:add-to-timeline></fb:add-to-timeline>
<form>
<input type="button" value="Publish" onclick="postArticle()" />
</form>
在我的 Open Graph 设置中,我的操作类型为“读取”以及对象类型为“文章”。
为什么这对我不起作用?
【问题讨论】:
标签: javascript facebook facebook-opengraph facebook-timeline