向时间线发布操作困难 [英] Difficulty posting Actions to Timeline

本文介绍了向时间线发布操作困难的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Facebook的开放式图表教程中,我已经尝试构建我们下一个应用程序的基础/ a>但是由于某些原因,我收到错误,不管我如何尝试POST动作。

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.

我已经定义了一个战斗操作和英雄对象,使用默认设置设置每个对象。 transcendgame 是我的命名空间。

I've defined a battle action and a hero object using the default settings when setting up each. transcendgame is my namespace.

$ id 是Facebook用户的用户标识我试过使用/ me /,直接的id对于我来说一直没有太多的问题)。

$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 是一个urlencoded字符串,指向具有以下内容的单独网页:

$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]">

应用程序画布页面包含以下代码。它应该为用户的时间轴POST一个新的动作事件,但一直给我发生错误。我也尝试了与样品英雄对象(samples.ogp.me ...)同样的问题。

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>

我正在调用JS SDK并正确运行fb.init。我真的不知道问题在哪里,更不用说如何解决它。

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.

编辑:我已经正确添加了用户的访问令牌到API调用:

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'.

这是奇怪的,因为网页确实有og:类型设置正确,如前面列出的这个问题,这是一些Facebook打嗝我需要解决?

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 :修正了最终的问题。

SECOND EDIT: Fixed the final problem.

og:url 我假设指向应用程序c的URL anvas,但它需要引用本身。例如,如果您的对象位于mydomain.com/object1.php,那么代码必须是:

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">

希望这有助于他人。

推荐答案

我有同样的问题,我更改了回调更有用:

I have the same problem and I changed the callback to be more helpful:

  var fb_url = '/me/YOUR_NAMESPACE?key=value';
  FB.api(fb_url,'post',
    function(response) {
      console.log(response);
      if (!response || response.error) {
        var msg = 'Error occured';
        if (response.error) {
          msg += "\n\nType: "+response.error.type+"\n\nMessage: "+response.error.message;
        }
        alert(msg);
      } else {
        alert('Post was successful! Action ID: ' + response.id);
      }
    }
  );

更新

我终于收到了一篇文章到时间轴,我所做的更改是使用BETA版本的JavaScript SDK。 ( https://developers.facebook.com/support/beta-tier/

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/ )

使用此选项:

<script src="//connect.beta.facebook.net/en_US/all.js#appId=xxx&amp;xfbml=1"></script>

而不是这样:

<script src="//connect.facebook.net/en_US/all.js#appId=xxx&amp;xfbml=1"></script>

这篇关于向时间线发布操作困难的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆