难以将操作发布到时间线
我尝试按照 Facebook 的开放图谱教程构建我们下一个应用程序的基础但由于某种原因,无论我如何尝试发布操作,我都会收到错误。
我将在这里尽可能深入地讨论,因为我希望这对所有掌握新时间轴的开发人员非常有用。
我在设置每个动作时使用默认设置定义了一个战斗动作和一个英雄对象。 transcendgame 是我的命名空间。
$id
是 Facebook 用户的 userid(我尝试过使用 /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">
希望这对其他人有帮助。
I've tried building the basis of our next app following Facebook's Open Graph Tutorial but for some reason I'm getting errors thrown at me regardless of how I try POSTing an action.
I'll go as in-depth as I can here as I hope it'll be very useful for all developers getting to grips with the new Timeline.
I've defined a battle action and a hero object using the default settings when setting up each. transcendgame is my namespace.
$id
is the userid of the Facebook user (I've tried using /me/, the direct id has always been less problematic in the past for me).
$herourl
is an urlencoded string pointing to a separate webpage with the following content:
<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]">
The application canvas page contains the following code. It should POST a new action event to the user's timeline, but is consistently giving me "Error occured". I have also tried it with the sample hero object (samples.ogp.me...) with the same problem.
<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>
I'm calling the JS SDK and running fb.init correctly. I honestly don't know where the problem even lies, let alone how to fix it.
EDIT: I've correctly added the user's access token to the API call:
FB.api('/me/transcendgame:battle' +
'?hero=<?=$herourl?>&access=<?=$token?>','post',
However, I'm getting the following error:
Type: OAuthException
Message: (#3502) Object at URL [url] has og:type of 'game'. The property 'hero' requires an object of og:type 'transcendgame:hero'.
This is odd, as the webpage definitely does have og:type set correctly, as listed earlier in this question. Is this some Facebook hiccup I need to work around?
SECOND EDIT: Fixed the final problem.
The og:url I had assumed to point back to the URL of the app's canvas, but it needs to reference itself instead. For instance, if your object is on mydomain.com/object1.php then the code must be:
<meta property="og:url" content="http://www.mydomain.com/object1.php">
Hope this helps others.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我有同样的问题,我更改了回调以使其更有帮助:
更新
我终于在时间轴上发布了一个帖子,我必须做出的更改是使用 JavaScript SDK 的 BETA 版本。 (https://developers.facebook.com/support/beta-tier/)
使用这个:
而不是这个:
I have the same problem and I changed the callback to be more helpful:
UPDATE
I finally got a post to the timeline, and the change I had to make was to use the BETA version of JavaScript SDK. ( https://developers.facebook.com/support/beta-tier/ )
Use this:
Instead of this:
我最初发帖时也遇到了一些困难。
我的问题在于操作的配置设置。
确保您的操作设置为针对确切的对象。
以下是我已设置和工作的一些屏幕:
如果这些设置正确,请检查从 facebook 返回的错误代码,将其发布到此处,我可以为您提供进一步帮助。
i had some difficultly posting initially as well.
My problem lied the configuration settings of the action.
Make sure that your actions are set to be for the exact object.
Here are some screens of what I have set up and working:
If these settings are correct, check the error code that comes back from facebook, post it here and i can help you further.
关于 og:url 的最后一点——这是正确的。您通常可以将 OG URL 视为图表中对象的“主键”。
Regarding the final point on og:url -- that's correct. You can generally consider the OG URL to be the "primary key" of an Object in the Graph.
为了消除一些可能的混淆,
og:url
并不“HAVE
”与url< 相同的
URL
/code>object1.php
页面。需要注意的重要一点是,无论您在那里引用什么URL
,它都必须在html 中具有
。META
标记; 页面的例如,我将画布页面的
URL
放在那里,以便当有人单击时间轴上操作中的超链接时,它会打开该页面。只要对象的'Get Code'
链接中的META
信息位于头部,您就不会收到错误。To clear up some possible confusion, the
og:url
doesn't "HAVE
" to be the sameURL
as theurl
of yourobject1.php
page. The important thing to note is that regardless of theURL
that you reference there, it has to have theMETA
tags in thehtml <head>
of the page.I, for example, put the
URL
of a canvas page in there so that when someone clicks the hyperlink in the action on the timeline it opens that page. As long as theMETA
information from the'Get Code'
link for the Object is in the head, you won't get the error.