简体   繁体   中英

Comment on Facebook page posts as page owner with extended token

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?

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM