Difficulty posting Actions to Timeline

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.


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 += "nnType: "+response.error.type+"nnMessage: "+response.error.message;
        }
        alert(msg);
      } else {
        alert('Post was successful! Action ID: ' + response.id);
      }
    }
  );

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:

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

Instead of this:

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

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.


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.

链接地址: http://www.djcxy.com/p/60022.html

上一篇: 行动不会出现在时间表上

下一篇: 难以发布行动到时间表