Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Javascript SDK open-graph: error adding custom objects for custom stories

I've created a custom object, called 'Opinion' to build custom stories around it.

I'm trying to add some app-owned objects from my website using the javascript sdk.

The sample code facebook gives me is:

FB.api(
  'me/objects/[namespace]:opinion',
  'post',
  {
    app_id: xxxxxxxx,
    type: "[namespace]:opinion",
    url: "http://samples.ogp.me/331257847005141",
    title: "Sample Opinion",
    image: "https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png",
    description: ""
  },
  function(response) {
    // handle the response
  }
);

The reponse is an error (OAuth Exception):

2500: Cannot specify type in both the path and query parameter.

If i remove the type parameter, i get another error:

(#100) The parameter object is required

Same if I remove [namespace]:opinion from the path.

I don't understand why, and there's no reference about this after googling it.

Why this? Any resource i can refer to solve that?

like image 587
apelliciari Avatar asked Jun 17 '13 17:06

apelliciari


1 Answers

The object is a JSON-encoded version of an object, the sample code generated for you was incorrect. Also remove type from the parameter list.

So something like,

FB.api(
  'me/objects/[namespace]:opinion',
  'post',
  {
    object: {"app_id":xxx,"url":"http:\/\/samples.ogp.me\/331257847005141","title":"\"Sample Opinion\"","image":"https:\/\/s-static.ak.fbcdn.net\/images\/devsite\/attachment_blank.png","description":"\"\""}
  },
  function(response) {
    // handle the response
  }
);

An example of how it looks can be seen at http://philippeharewood.com/facebook/objectify.html and it was based off the curl example given at https://developers.facebook.com/docs/opengraph/using-object-api/

like image 171
phwd Avatar answered Nov 11 '22 18:11

phwd