0

I am not using the Javascript SDK because that is client-side whereas I'm making a server-side call.

I want to make a page post so that I can make an ad creative with it. I can do the call perfectly fine in the Graph API Explorer tool, but I cannot make the same call (with the same long-lived access tokens that continue to work in the Graph Explorer) from Javascript. Here is my code:

  tok = <valid and never expiring user token>;
  var pg_tok = <valid and never expiring page token>;
  var act_id = <account_id>;
  var pg_id = <page_id>;
  var call_to_action = 'INSTALL_MOBILE_APP';
  var fb_app_url = 'https://itunes.apple.com/us/app/id284882215';
  var msg = 'Test creative, ya see';
  var pic_url = 'https://s3.amazonaws.com/<path_to_my_image>';

  var ROOT = 'https://graph.facebook.com/';
  var pagepost_endpoint = ROOT+pg_id+'/feed';
  console.log(pagepost_endpoint);
  var pagepost_params = {
    access_token: pg_tok,
    call_to_action: {
      type: call_to_action,
      value: {link: fb_app_url}
    },
    message: msg,
    picture: pic_url,
    published: false
  };
  console.log(pagepost_params);

  var pagepost_res = HTTP.post(pagepost_endpoint, {params: pagepost_params});
  console.log(pagepost_res);

I have played around a bunch with params vs. data for where pagepost_params goes in the HTTP.post that is giving the error (that is Meteor's HTTP btw).

-Putting everything in params gives the error: {"error":{"type":"Exception","message":"No Call To Action Type was parseable. Please refer to the call to action api documentation","code":1373054,"is_transient":false}}.

-Putting everything in data gives the error: {"error":{"message":"(#200) This API call requires a valid app_id.","type":"OAuthException","code":200}}.

-Putting access_token in params and everything else in data gives the error: {"error":{"message":"Invalid parameter","type":"FacebookApiException","code":100,"error_subcode":1349125}}.

One more clue for everyone, if I change the HTTP.post to HTTP.get, and just put access_token in params and include no other parameters (in params or in data), the call succeeds and I see past posts I have made on this page through the Graph Explorer (only the ones with published: true, though), so the access token and endpoint do work, just something is faulty about POST-ing instead of GET-ing and the specific parameters I'm using.

tscizzle
  • 11,191
  • 15
  • 54
  • 88

2 Answers2

0

Have you tried posting to /photos instead of /feed? The error subcode is the same as mentioned here Posting to facebook wall using graph api

Hope this helps

Community
  • 1
  • 1
artur
  • 1
  • I successfully made the call in the Graph Explorer, so I know the endpoint is right. It is the same message, but the message "Invalid parameter" is pretty vague so the error message similarity is unfortunately not much evidence. – tscizzle Aug 04 '14 at 00:15
0

Turned out to be an issue with Meteor's HTTP. It does not handle nested JSON very well, and we're going to submit a pull request for that. But for those seeing this, the important thing to take away is that the call_to_action may not be a valid JSON object, and even if it is, it may not be being stringified/parsed as expected. My fix was using request.post instead of HTTP.post. (then instead of params or data, you use form. look up node's request https://github.com/mikeal/request)

tscizzle
  • 11,191
  • 15
  • 54
  • 88