我正在创建一款支持 Facebook 的游戏,用户可以在其中发布“好友通行证”;玩家将能够(自动)发布诸如:“我在 MY_GAME 上超过了 James Brown”。我正在使用 Open Graph 来发布我的操作。我创建了一个名为“pass”的操作和一个名为“friend”的对象。这是我的属性(其中“friendpass”是 friend 引用):
我正在尝试发布诸如“Michael 在 MY_GAME 上超越了一位 friend ”之类的操作,并标记我超越的 friend 。我怎样才能启用此功能?目前,我已经设置了一个页面(实际上只是元标记)呈现器,这是一个呈现页面的示例:
<html and other headers...>
<meta property="fb:app_id" content="345390505541783">
<meta property="og:type" content="smileys-game:friendpass">
<meta id="ogurl" property="og:url" content="http://apps.canpoyrazoglu.com/smileys/pass/mehmet/sucuk">
<meta property="og:title" content="Friend passed!">
<meta property="og:image" content="https://s-static.ak.fbcdn.net/images/devsite/attachment_blank.png">
<meta id="friendid" property="smileys-game:friend" content="735475141">
<meta id="ogdesc" property="og:description" content="something comes here.">
<rest of header and page...>
我使用调试工具来获取 Facebook 看到的内容,并且有一个指向操作的链接作为图形 API 调用。当我单击它时,它返回 OAuth 错误,当我将该 URL 键入 Graph API 资源管理器时,我得到以下信息:
Graph API 将我的“ friend ”对象视为网页,这实际上是对 Facebook ID(我自己的 ID)的引用。我如何利用该 friend ID 并在帖子中创建指向该 friend 的链接?
谢谢, 可以。
最佳答案
当您创建操作类型时,您需要使用profile
对象类型(也称为连接对象类型)。在这里,我创建了动词“高五”一个人:
对象类型将自动配置,因为profile
是内置的、FB提供的对象类型。因此,您不必配置对象类型,除非您需要高级设置。
然后创建一个聚合:
对象的 og 元标记需要使用类型 profile
(本例的文件路径是/og/profile2.html):
<head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# high_fiver: http://ogp.me/ns/fb/high_fiver#">
<meta property="fb:app_id" content="27877347222" />
<meta property="og:url" content="http://www.rottentomatoes.com/celebrity/tom_hanks/" />
<meta property="og:type" content="profile" />
<meta property="og:title" content="Tom Hanks" />
<meta property="og:description" content="Tom Hanks profile on RT" />
<meta property="og:image" content="http://content6.flixster.com/rtactor/40/37/40376_pro.jpg" />
请注意,您可以指向任何配置文件
,而不仅仅是 FB 配置文件。上面,我使用的是 Tom Hanks 在烂番茄上的个人资料,该个人资料使用 Open Graph 并具有 og:type profile
。
我发布这样的操作:
<script type="text/javascript">
function postAction() {
FB.api(
'/me/high_fiver:high_five' + '?profile=http://www.plooza.com/og/profile2.html',
'post',
function(response) {
if (!response || response.error) {
alert('Error occured');
console.log(response.error);
} else {
alert('Post was successful! Action ID: ' + response.id);
}
}
);
}
</script>
最后,我的应用程序的用户将在他/她的时间轴上(以“时间轴单元”)发布 OG 故事:
当您点击故事单元中的“汤姆·汉克斯”链接时,它会加载烂番茄资料。
您可以在这里尝试这个演示应用程序:http://plooza.com/og/profile2.html
关于facebook - 如何在 Open Graph 中引用好友?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12043046/