【问题标题】:using facebook batch request javascript api使用 facebook 批量请求 javascript api
【发布时间】:2013-02-18 10:01:56
【问题描述】:

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

【问题讨论】:

  • 我认为在使用/访问 FB Graph API 的某些部分时,您需要以某种方式验证您的请求。 OAuthException 似乎表示授权错误。
  • 第一个请求顺利进行,没有错误,第二个请求得到错误..即使我在单独的 API 请求中执行它,它也可以工作 FB.api('/me/feed', ' post', opts, function(response) { if (!response || response.error) { } else { } });
  • 发现问题及解决方法:body字段。这应该格式化为原始 HTTP POST 正文字符串,类似于 URL 查询字符串 github.com/jgorset/facepy/issues/55

标签: javascript facebook api batch-file request


【解决方案1】:

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

效果很好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-31
    相关资源
    最近更新 更多