facebook - 如何在 Open Graph 中引用好友?

标签 facebook facebook-graph-api facebook-opengraph

我正在创建一款支持 Facebook 的游戏,用户可以在其中发布“好友通行证”;玩家将能够(自动)发布诸如:“我在 MY_GAME 上超过了 James Brown”。我正在使用 Open Graph 来发布我的操作。我创建了一个名为“pass”的操作和一个名为“friend”的对象。这是我的属性(其中“friendpass”是 friend 引用):

pass action

我正在尝试发布诸如“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 call result

Graph API 将我的“ friend ”对象视为网页,这实际上是对 Facebook ID(我自己的 ID)的引用。我如何利用该 friend ID 并在帖子中创建指向该 friend 的链接?

谢谢, 可以。

最佳答案

当您创建操作类型时,您需要使用profile对象类型(也称为连接对象类型)。在这里,我创建了动词“高五”一个人:

action type config

对象类型将自动配置,因为profile是内置的、FB提供的对象类型。因此,您不必配置对象类型,除非您需要高级设置。

然后创建一个聚合:

aggregation config

对象的 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 故事:

profile story unit

当您点击故事单元中的“汤姆·汉克斯”链接时,它会加载烂番茄资料。

您可以在这里尝试这个演示应用程序:http://plooza.com/og/profile2.html

关于facebook - 如何在 Open Graph 中引用好友?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12043046/

相关文章:

facebook - 有没有办法让 -webkit-border-radius 在 Facebook 中工作?

javascript - facebook - 通过 ajax 点赞帖子

seo - 开放图描述元标记在 LinkedIn 中不起作用

facebook - 如何实现OG-Tags的国际化?

javascript - 如何在应用程序浏览器中强制链接或页面在 facebook 之外打开?

ios - Facebook Friend Picker 示例无法使用开箱即用的 IOS

android - 使用图形 API 获取 Facebook 页面事件

Facebook - 元标签(打开图)

redirect - 如何通过 301 重定向移动 URL 并保留页面的 Facebook 点赞和 Open Graph 信息?

javascript - 将自定义文本传递给新的 Facebook 共享器按钮