0

I'm developing a node.js app which manages a Facebook page among other functionalities.

To comment on user submitted posts, I use the following code in node.js:

FB.api(object + '/comments','post',
  { message: COMMENT_I_WANT_TO_SUBMIT, access_token: MY_PAGE_ACCESS_TOKEN },
  function(res){ 
    // deal with res
  }
);

When using my short-lived Facebook page access-token (which I get from Graph API Explorer) the comment submitted is shown as a comment submitted by the page itself (what I want), but when I use my permanent token it is shown as submitted by myself (page owner).

To get this permanent token I followed these instructions: https://stackoverflow.com/a/28418469/4713311

The token has my name associated to it since I had to grant permissions to manage the pages I own to generate the token. I believe this token has the proper permissions since the token debugger shows the following permissions in scope: "manage_pages, publish_pages, publish_actions, public_profile"

Is there any way I can use this never expiring token to comment on posts with the page name instead of my own?

Community
  • 1
  • 1
  • Debug your access token using https://developers.facebook.com/tools/debug/ – if it does not list a “Profile ID” in addition to the “User ID”, then it is _not_ a page access token. – CBroe May 15 '15 at 20:26
  • Indeed the token I'm using has no "Profile ID" associated. It has the "App ID" and my "User ID". How can my token have this "Profile ID"? Doesn't the link I provided in the main question only extend my current short term token? Thanks in advance – Leonel Araújo May 15 '15 at 20:44
  • That just means you did not get a page access token in the first place then. How to get an extended page access token, is clearly described in the docs: https://developers.facebook.com/docs/facebook-login/access-tokens#extendingpagetokens – CBroe May 15 '15 at 20:46
  • I've already solved and will explain in a separate answer, but that wasn't the problem because as I've stated in my main question, I had already successfully used my short-lived page access token and comment as the page and not as myself. The problem was with the process of extending the token which is where that link came in handy. I had already read that docs section but somehow I didn't interpret correctly. Thanks for your time. – Leonel Araújo May 15 '15 at 21:23
  • _“but that wasn't the problem”_ – pretty sure the problem _was_ that your _extended_ token was not a page access token. If you do things in the extension process in the wrong order, then you won’t get an extended page access token, but end up with an extended user token only. – CBroe May 15 '15 at 21:29
  • When you said "in the first place" in your second reply I thought you meant "you short-lived token" and not "in your first try", which confused me. After I got the answer I understood what you meant with it, but at first sight it wasn't clear. – Leonel Araújo May 15 '15 at 21:48

1 Answers1

0

A Page Access Token should have not only "User ID" but also "Profile ID" associated, which wasn't the case for the extended page access token.

A Page Access Token isn't "extendable", to get a permanent page access token I had to request one with a permanent User Access Token, as explained here

Using as short-lived access token I got from Graph API Explorer (Select App -> Get Token -> Select permissions manage_pages, publish_pages, publish_actions and other you may need -> Grab the token that fills the "Access Token" text box) I made the following call to extend the token. https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token&client_id={app-id}&client_secret={app-secret}& fb_exchange_token={short-lived-token}

Using the token returned, you can simply call /me/accounts and copy the page's access_token This token is a permanent Page Access Token, to confirm you can use the token debugger and verify it has your "User ID" and your page's "Profile ID"