问题
Does anyone know how to install Facebook Chatbot on the page that you don't own?
I have created a chatbot and want to allow other FB Page to install my chatbot app, I can generate page_access_token for the FB Page that I admin, but how to get the page_access_token for the FB Page that I am not the admin?
Thanks!
Joel
回答1:
Based on my understanding of the docs, your Fb app needs to implement Facebook Login. The admin of the page will need to "login" to your app and grant your app access to the manage_pages permission. Once you get that permission, you can then request for the page access token with a separate API call.
See the table regarding page access tokens: These access tokens are similar to user access tokens, except that they provide permission to APIs that read, write or modify the data belonging to a Facebook Page. To obtain a page access token you need to start by obtaining a user access token and asking for the
manage_pagespermission. Once you have the user access token you then get the page access token via the Graph API.Page access tokens: Page access tokens are used in Graph API calls to manage Facebook Pages. To generate a page access token, an admin of the page must grant an extended permission called
manage_pages. Once this permission has been granted, you can retrieve the page access token using the following Graph API request...manage_pages: Enables your app to retrieve Page Access Tokens for the Pages and Apps that the person administrates.
回答2:
Here are the steps that i am following to subscribe a page to generate long lived page token (that never expires).
- Normal Facebook login with extra scopes
manage_pages,pages_show_list,public_profile,pages_messagingscopes. On a server side api call, we extend the short term token to make it a long-lived token.
List all the user pages using the account API. [GET]
${FB_BASE_URL}/me/accounts?access_token=${accessToken}&fields=picture,id,name,access_token,username,permsAllow the user to select one of the pages and then you can use the subscribe API to subscribe that page to our application. [POST]
${FB_BASE_URL}/${page.id}/subscribed_apps?access_token=${page.access_token};
Notes:
- from accounts API each page will have a unique access_token, you will need to store this token somewhere to use later when replying to messenger, set get started button action, persistent menu,,, etc.
- you need to extend the login access token in order to get page_access token that does not expire.
- in that case all of your clients pages will be connected to a one Facebook application that will be connected to one bot, on your bot you will need to change the bot behavior depending on the recipient id (Page ID).
- In order to subscribe a page to an app the user should have "ADMINISTER" perms on that page, that's why you need to get the perms field in the account API and filter the results.
来源:https://stackoverflow.com/questions/38319028/chatbot-generate-page-tokens-for-the-pages-you-dont-own-using-facebook-login