How to use Facebook Graph API with Django ?

Hi all,
please help me with pointing me into right direction…

How to use Facebook Graph API with Django ?

I need to connect to Facebook and get information about Events on my Page - so very basic usage.

I did not find such a topic on this forum. Also I tried to search Internet, but most information seems quite outdated (for Django < 2 and I want to use Django 3). I found some packages for Django but seems outdated.

So kindly asking if you have any suggestion which package to use in 2020 or where to read about that topic.

Thank you !!!

Retrieving data from another web site isn’t, strictly speaking, a function of Django.

You can add code in a view to make that call to retrieve the data, but that would be done using some other library, such as requests, to issue the http request to the Facebook API.

In part, the answer will depend upon whether you want this to be done on a regularly-scheduled basis (such as once-per-day), or “on-demand” when the view is invoked.


Let me put what I did in case someone comes to this page.

I simply installed facebook-sdk, imported it and use get_object method to retrieve what I need.
Of course, you need valid token but that’s another story :slight_smile:

Use this to install the package:

pip install facebook-sdk

Then use this code to fetch events:

import facebook

token = {"<token>"}
graph = facebook.GraphAPI(token)