Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using facebook batch request javascript api

Im trying to send batch request to graph api, and getting error in the response for the second request:

"{
   "error": {
      "message": "(#100) Missing message or attachment",
      "type": "OAuthException",
      "code": 100
     }
}"

Can anyone tell me what am I doing wrong?

Here is the code I use:

var opts = {
               message : 'Some message',
               name : 'Post Name',
               link : 'url',
               description : 'The post Description',
               picture : 'url to image'
           };

FB.api('/', 'POST', {
         batch: [
              { method: 'GET', relative_url: 'me/friends'},
              { method: "POST",relative_url: "me/feed", body : opts }
         ]
       }, function (response) {
                console.log(response);
       });
like image 798
Sharon Abu Avatar asked Feb 18 '13 10:02

Sharon Abu


1 Answers

Like Sharon said, you need to put the body field in a url encoded way.

You can do it simple with jquery, like:

var opts = {
               message : 'Some message',
               name : 'Post Name',
               link : 'url',
               description : 'The post Description',
               picture : 'url to image'
           };

FB.api('/', 'POST', {
         batch: [
              { method: 'GET', relative_url: 'me/friends'},
              { method: "POST",relative_url: "me/feed", body : $.param(opts) }
         ]
       }, function (response) {
                console.log(response);
       });

Works good.

like image 54
Julio Popócatl Avatar answered Sep 17 '22 02:09

Julio Popócatl