Does anyone know any good Facebook Graph API Python SDK to retrieve insight metrics such as:
- Lifetime Post Total Reach
- Lifetime Post organic reach
- Lifetime Post Paid Reach
- Lifetime Post Total Impressions.
and many more, because I couldn’t find any good python SDK with well-written documentation.
3
Answers
Use the Facebook SDK Available for Python
I’ll advise you to use the facebook-sdk module available. It has great documentation, and I’m sure you’ll find all the GraphAPI Options available there.
https://pypi.python.org/pypi/facebook-sdk
Thanks!
First of all, you have to apply for read_insight permissions to retrieve all of these insight parameters. After that use, the python SDK mentioned by @monkfromearth and the code to get insights using SDK is:
In the since and until parameters mentioned in field parameter, here you will provide the start date and date to retrieve data between otherwise Facebook Graph API will provide you data of last 93 days.
In this step, you will initiate the GraphAPI object of Facebook Python SDK and then call the get_object method with parameters page_id from which you want the insights to be retrieved and fields parameter to retrieve insights fields from the page. In response, you will get the desired insights attributes you had mentioned in the field parameter.
I was able to get by generating this below URL:
https://graph.facebook.com/page_id/posts?fields=insights.metric(post_impressions_organic,post_impressions_organic_unique,post_video_views_organic,post_clicks_by_type)&access_token=USER_ACCESS_TOKEN