【问题标题】:Looks like Meteor.http.post is not working properly看起来 Meteor.http.post 工作不正常
【发布时间】:2014-06-09 05:11:51
【问题描述】:

我正在尝试从 Meteor 应用程序的服务器端在用户的 Facebook 提要上发帖:

result = Meteor.http.call 'POST',
    "https://graph.facebook.com/#{facebook_id}/feed?access_token=#{app_access_token}",
    { data: { message: "some message", link: "http://www.somelink.com" } }

结果如下:

{"statusCode":400,"content":"{\"error\":{\"message\":\"(#100) Missing message or attachment\",\"type\":\"OAuthException\",\"code\":100}}","headers":{"access-control-allow-origin":"*","cache-control":"no-store","content-type":"text/javascript; charset=UTF-8","expires":"Sat, 01 Jan 2000 00:00:00 GMT","pragma":"no-cache","www-authenticate":"OAuth \"Facebook Platform\" \"invalid_request\" \"(#100) Missing message or attachment\"","x-fb-rev":"710505","x-fb-debug":"doa24fNWaPsogxv4HmXa1/5KA30BBct86VZWVeYsins=","date":"Fri, 11 Jan 2013 13:57:52 GMT","connection":"keep-alive","content-length":"95"},"data":{"error":{"message":"(#100) Missing message or attachment","type":"OAuthException","code":100}},"error":{}}

我试图在 Facebook 调试器中重现这个问题 - 只有当我没有在 POST 正文中发送任何参数时,我才会收到相同的消息。会不会是 Meteor.http.call 中 POST 实现的问题?

【问题讨论】:

  • 你试过用params代替data吗?

标签: meteor


【解决方案1】:

您在 HTTP POST 请求内容正文 data 中发送数据,您需要使用 params 将正确的变量作为 postdata 传递

试试

result = Meteor.http.post(
   "https://graph.facebook.com/#{facebook_id}/feed?access_token=#{app_access_token}",
   { params: { message: "some message", link: "http://www.somelink.com" } } );

另外,如果您在 Meteor.methods 存根中进行此操作,请尝试使用 this.unblock();,以便可以同时进行其他操作

更新:较新版本的meteor使用HTTP而不是Meteor.http,上面的代码将替换为HTTP.post

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-30
  • 1970-01-01
  • 2021-08-15
  • 2022-01-03
  • 1970-01-01
相关资源
最近更新 更多