看起来像Meteor.http.post工作不正常

Vla*_*dev 4 meteor

我正试图从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" } }
Run Code Online (Sandbox Code Playgroud)

结果得到以下结果:

{"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":{}}
Run Code Online (Sandbox Code Playgroud)

我尝试在Facebook调试器中重现这个问题 - 只有在POST主体中没有发送任何参数时才会收到相同的消息.这可能是Meteor.http.call中POST实现的问题吗?

Aks*_*hat 10

您要在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" } } );
Run Code Online (Sandbox Code Playgroud)

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

更新:使用较新版本的流星HTTP代替Meteor.http,上面的代码将HTTP.post替换掉.

  • 请注意,有时您需要使用`data`而不是`params`.在这个问题上看到我的答案.(http://stackoverflow.com/questions/26998140/gmail-rest-api-mark-message-as-read/30201963#30201963) (2认同)