4

I'm trying to post on a user's facebook feed from the server side of Meteor app:

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" } }

I got the following as a result:

{"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":{}}

I tried to reproduce this problem in Facebook debugger - I got the same message only if I do not send any parameters in POST body. Could it be the problem of POST implementation in Meteor.http.call?

Vladimir Lebedev
  • 1,207
  • 1
  • 11
  • 25

1 Answers1

10

You're sending your data in the HTTP POST request content body data, you need to use params to pass the correct variables on as postdata

try

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

Also if you're diong this in a Meteor.methods stub try using this.unblock(); so that other operations can occur simultaneously

Update: The newer versions of meteor use HTTP instead of Meteor.http, the code above would go as HTTP.post as a drop in replacement.

Tarang
  • 75,157
  • 39
  • 215
  • 276
  • 2
    Note that sometimes you need to use `data` instead of `params`. See my answer on this SO question. (http://stackoverflow.com/questions/26998140/gmail-rest-api-mark-message-as-read/30201963#30201963) – philcruz May 12 '15 at 21:52
  • Yes, sometimes you need to use data instead of params. See this other example: https://stackoverflow.com/questions/11205270/meteor-http-call-method – steph643 May 12 '17 at 11:26