使用 facebook 批量请求 javascript api [英] using facebook batch request javascript api

查看:36
本文介绍了使用 facebook 批量请求 javascript api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向图形 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?

这是我使用的代码:

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 编码的方式中.

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

你可以用 jquery 来做,比如:

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

效果很好.

这篇关于使用 facebook 批量请求 javascript api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆