我已经尝试按照Facebook 的 Open Graph Tutorial构建我们的下一个应用程序的基础,但由于某种原因,无论我如何尝试发布操作,我都会收到错误消息。
我将在这里尽可能深入,因为我希望它对所有掌握新时间轴的开发人员都非常有用。
我在设置时使用默认设置定义了一个战斗动作和一个英雄对象。transcendgame是我的命名空间。
$id
是 Facebook 用户的用户 ID(我尝试过使用 /me/,过去对我来说直接 ID 的问题一直较小)。
$herourl
是一个 urlencoded 字符串,指向具有以下内容的单独网页:
<head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# transcendgame: http://ogp.me/ns/fb/transcendgame#">
<meta property="fb:app_id" content="[my id]">
<meta property="og:type" content="transcendgame:hero">
<meta property="og:url" content="http://apps.facebook.com/transcendgame/">
<meta property="og:title" content="Hercules">
<meta property="og:description" content="As this game is still in development, you can ignore this feed post!">
<meta property="og:image" content="[an image url]">
应用程序画布页面包含以下代码。它应该向用户的时间线发布一个新的操作事件,但一直给我“发生错误”。我也用同样问题的示例英雄对象(samples.ogp.me ...)进行了尝试。
<script>
function doTest()
{
FB.api('/<?=$id?>/transcendgame:battle' +
'?hero=<?=$herourl?>','post',
function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post was successful! Action ID: ' + response.id);
}
});
}
</script>
<a href="#" onclick="doTest(); return false">Test fb post</a>
我正在调用 JS SDK 并正确运行 fb.init。老实说,我什至不知道问题出在哪里,更不用说如何解决了。
编辑:我已将用户的访问令牌正确添加到 API 调用中:
FB.api('/me/transcendgame:battle' +
'?hero=<?=$herourl?>&access=<?=$token?>','post',
但是,我收到以下错误:
Type: OAuthException
Message: (#3502) Object at URL [url] has og:type of 'game'. The property 'hero' requires an object of og:type 'transcendgame:hero'.
这很奇怪,因为网页确实正确设置了 og:type,如本问题前面所列。这是我需要解决的一些 Facebook 问题吗?
第二次编辑:修复了最后一个问题。
我假设的og:url指向应用程序画布的 URL,但它需要引用自身。例如,如果您的对象在 mydomain.com/object1.php 上,那么代码必须是:
<meta property="og:url" content="http://www.mydomain.com/object1.php">
希望这对其他人有帮助。