Facebook Graph API in Python

Exhibit 25.8 demonstrates the Python implementation of the Facebook Graph API to retrieve posts from Facebook. Similar to Twitter API Tutorial, you need to import the relevant libraries, set the parameters including the endpoint URL, and execute the requests.get command to retrieve the posts.

Facebook Graph API Tutorial
import requests
import json

params = {'access_token': 'ENTER_ACCESS_TOKEN'}
url = 'https://graph.facebook.com/v19.0/'
page_id = 'me'  
page_info = "/feed"
page_url = url + page_id + page_info

result = requests.get(page_url, params=params)

data = result.json()
for element in data['data']:
    print(element['message'])

Exhibit 25.8 Facebook Graph API code to retrieve posts from Facebook feed.


Previous     Next

Use the Search Bar to find content on MarketingMind.