Skip to content

Latest commit

 

History

History
64 lines (46 loc) · 2.39 KB

facebook.md

File metadata and controls

64 lines (46 loc) · 2.39 KB

Post a message to a page

📚 Facebook Pages API

  1. register on developers.facebook.com
  2. create an app: choose Other -> Business, don't link any "Business portfolio"
  3. 🏁 as soon as you reach Add products to your app, the app is ready
  4. open the Graph Explorer
  5. from the Meta App dropdown, select your just-created-app
  6. grant the following permissions: pages_manage_metadata, pages_manage_posts, pages_show_list
  7. from the User or Page dropdown, select Get Page Access Token | this will start a wizard to grant access to the page you want to post to
  8. from the User or Page dropdown, select your Page
  9. click Generate Access Token

Submit and you'll get the id and name of the Page:

{
    "id": "10...45",
    "name": "TLI Test Channel"
}

This is a SHORT-LIVED (~2 hours) token. Input it into the Access Token Debugger and click Extend Access Token. This generates a LONG-LIVED (~2 months) token.

Now go back to the Graph Explorer. From the User or Page dropdown, select User Token. Submit and you'll get your own user-id:

{
  "id": "10...99",
  "name": "Gianluigi NeverEnough Zanettini"
}

Customize this cURL request and fire it away:

curl -i -X GET "https://graph.facebook.com/v19.0/{user-id}/accounts?access_token={long-lived-access-token}"

This will return a JSON with a access_token fields. That token should be never-expiring: test it with the Access Token Debugger and you should get:

Expires: Never

Data Access Expires: 1719608325 (in about 3 months)

(don't mind the Data Access Expires: it's not need just to post)

  1. copy the variables to your local .env file.
  2. assign the never-expiring token (the last one) and page ID values to the variables

You can now post a message on the page with

$messenger->sendMessageToPage($messageText)`

Or share a URL:

$messenger->sendUrlToPage('https://turbolab.it')`

👉 Check the example here