Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/459.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用facebook批量请求javascript api_Javascript_Facebook_Api_Batch File_Request - Fatal编程技术网

使用facebook批量请求javascript api

使用facebook批量请求javascript api,javascript,facebook,api,batch-file,request,Javascript,Facebook,Api,Batch File,Request,我正在尝试向graph api发送批处理请求,第二个请求的响应中出现错误: "{ "error": { "message": "(#100) Missing message or attachment", "type": "OAuthException", "code": 100 } }" 谁能告诉我我做错了什么 以下是我使用的代码: var opts = { message : 'Some message',

我正在尝试向graph api发送批处理请求,第二个请求的响应中出现错误:

"{
   "error": {
      "message": "(#100) Missing message or attachment",
      "type": "OAuthException",
      "code": 100
     }
}"
谁能告诉我我做错了什么

以下是我使用的代码:

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);
       });

正如Sharon所说,您需要以url编码的方式放置body字段

使用jquery可以很简单地完成这项工作,如:

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);
       });

工作正常。

我认为在使用/访问FB Graph API的某些部分时,您需要以某种方式验证您的请求。OAuthException似乎表示一个授权错误。第一个请求进行得很顺利,没有错误,第二个请求得到了错误。即使我在单独的API请求中这样做,它仍然可以工作FB.API('/me/feed',post',opts,function(response){if(!response | | response.error){}else{});找到问题和解决方案:body字段。应将其格式化为原始HTTP POST正文字符串,类似于URL查询字符串