javascript - 使用 facebook 批量请求 javascript api

标签 javascript facebook api batch-file request

我正在尝试向图形 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说的,你需要把body字段用url编码的方式。

你可以用 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);
       });

效果不错。

关于javascript - 使用 facebook 批量请求 javascript api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14933641/

相关文章:

javascript - 谷歌图书 API

javascript - 将额外的参数传递给 reactjs 中的 onChange Listener

javascript - 我可以让浏览器忽略(CORS)规则吗?

javascript - 使用 Jquery 切换时完全替换类

javascript - Angular JS 在 Django 应用程序中已安装但未加载

facebook - 就像 Facebook 网站上的门控一样

ios - Facebook Unity SDK,损坏的 iOS 后处理器

ios - 断点 2.1 错误解析/Facebook iOS SDK

php - 无法使用下面的文本创建 QR

javascript - 在 javascript 中使用 python 输出