Facebook Integration

  • This tutorial will help configure the facebook graph API and integrate with facebook to read public posts
  • This tutorial reads the messages for the movie "Sultan"
  • This tutorial uses facebook-sdk, so install the sdk as follows before following the next steps
    • pip install facebook-sdk

Create Facebook App

  • Go to Facebook Apps dashboard
  • Then Click Add a New App -> Choose platform WWW -> Choose a new name for your app -> Click Create New Facebook App ID -> Create a New App ID -> Choose Category (I chose "Entertainment") -> Click Create App ID again.
  • Enter website url in the website url link and then go to the quick start link
  • Go back to Apps Review and make the app public
  • Go to Settings link and take note of App ID and App Secret
In [1]:
facebook_appid = ''
user_access_token = ''
In [2]:
import facebook

cfg = {
  "page_id"      : facebook_appid,
  "access_token" : user_access_token
}
In [6]:
import json
import pandas as pd
In [20]:
graph = facebook.GraphAPI(cfg['access_token'])

posts = graph.get_object("sultanthemovie"+"/posts")

posts_json = json.dumps(posts)
posts_dict = json.loads(posts_json)
In [21]:
idx = 1
id_lists = []
for i in posts_dict['data']:
  keys = list(i.keys())
  if "message" in keys:
      print( idx , ":" , i["message"] )
  if "story" in keys:
      print( idx , ":" , i["story"] )
  idx = idx + 1
  id_lists.append( i['id'])
1 : Dekho Sultan ka zabardast dhobi pachad, akhade mein aur jindagi mein. Book your tickets at - http://bit.ly/BookSultanTickets
2 : Sultan shared BollywoodHungama.com's live video.
3 : To watch Sultan ka dhamaakedar daav, book your tickets at - http://bit.ly/BookSultanTickets
4 : After achieving 1 million downloads on Play Store and being featured as a top game for Android devices, Sultan: The Game makes its way to iOS now. Download the game on App Store now : bit.ly/yrfsultangame
5 : Yo se Haryana ki Sherni! Watch Aarfa's contagious zest in #Sultan. BOOK YOUR TICKETS NOW http://bit.ly/BookSultanTickets
6 : Sultan shared Yash Raj Films - YRF's post.
7 : Make this Eid even more special with Sultan! Book your tickets at -  http://bit.ly/BookSultanTickets
8 : Shout OUT LOUD if you're loving #Sultan! To watch him in theatres near you, book tickets at  http://bit.ly/BookSultanTickets
9 : Participate in the #WatchingSultanThisEid contest by sending us pictures of your Sultan tickets & win a #Timex watch.
T&C apply - http://bit.ly/29giPbY
10 : Sultan shared Anushka Sharma's photo.
11 : As a special tribute for wrestlers, exclusive screenings were organised for them on the release day in Delhi, Pune and Indore. Sultan has been a role close to Salman Khan's heart and this is his way of appreciating the real life Sultans!
11 : Sultan added 11 new photos to the album: Sultan - Special Screenings For Wrestlers.
12 : Sultan updated their cover photo.
13 : Let the festivities begin with Sultan & Aarfa! Book your tickets at - http://bit.ly/BookSultanTickets
14 : Celebrate this Eid with SULTAN! Eid Mubarak :)
15 : See you in the ring! Book your Sultan tickets at - http://bit.ly/BookSultanTickets
16 : Overwhelming reviews all over! That's the power of SULTAN.
Book your tickets at - http://bit.ly/BookSultanTickets
17 : Their love for each other is their driving force! Watch Sultan & Aarfa's tale. Book your tickets at - http://bit.ly/BookSultanTickets
18 : Sultan in the wrestling ring & Sultan of hearts!
Laugh, cry & cheer for him in theatres now. Book your tickets at - http://bit.ly/BookSultanTickets
19 : Whistle & cheer 'coz Sultan has entered the ring! Watch his story unfold at theatres near you. Book your tickets at -  http://bit.ly/BookSultanTickets
20 : Sultan's power-packed punch is winning hearts all over! Have you watched it yet? Book your tickets for #Sultan at- http://bit.ly/BookSultanTickets
21 : You've got to watch it to believe it! Book your tickets for #Sultan right here - http://bit.ly/BookSultanTickets
22 : Sultan ka daav hai zabardast! Rave reviews pouring in.
Watch it at theatres near you. Book now- http://bit.ly/BookSultanTickets
22 : Sultan added 4 new photos.
23 : Sultan shared Yash Raj Films - YRF's post.
24 : Sultan updated their cover photo.
25 : THE BIG DAY IS HERE! Aa gaya hai SULTAN! Book your tickets at - http://bit.ly/BookSultanTickets
In [22]:
id_lists[0]
Out[22]:
'1580052648923018_1689945294600419'
In [23]:
comments = graph.get_object(id_lists[0]+"/comments")
comments_json = json.dumps(comments)
comments_dict = json.loads(comments_json)
# Each given id maps to an object.

idx = 1
id_lists = []
for i in comments_dict['data']:
  keys = list(i.keys())
  if "message" in keys:
      print( idx , ":" , i["message"] )
  idx = idx + 1
  id_lists.append( i['id'])
1 : Agar Rs.15000 - 50000 कमाना चाहते है तो .......आइये DIGITAL INDIA से जुड़िये......Zero investment.... JOIN होने के लिए आप  1⃣ अपने फ़ोन के play store में Champcash लिखो और उस app को अपने मोबाइल में install कर लो ! 2⃣ अब app पर click करो और sign up पर click करके अपनी डिटेल्स भर दो. 3⃣ Refer id of sponsor पूछेगा वहाँ पर 4670025 डाल दो  इस I'D ( 4670025 ) को खाली पेपर पर लिख लें आगे जरूरत पङेगी  4⃣ complete challenge aur apna id activate karke business se jud jao. WhatsApp no 9818766094
2 : super flop mere aamir ka record kbhi nhi tod paayega sala chddi wala
3 : ek no movie hai sultan
4 : Kia baat hai is movie ki
5 : Jhakass movie... RE  SULTAN...
6 : meri nazar me movir sirf 150 hi kma paaigi
7 : Wah kya jhakas movie h ...
8 : This is a good desi indian movie
9 : How talented salman is!
10 : 74 crore in 2 days
11 :
12 : Salman vai rockssz
13 : All time BLOCKBUSTERR ♡♡♡
14 : Right said
15 : Namste he 😂😂😂😂
16 : better than bajranfi bhaijaan?
17 : Super movie sultaan
18 : Superd 👈👈👈😍
19 : 800 CRORE🌟🌟🌟🌟🌟
20 : records thodegaa
21 : Nice movie
22 : bakwaas super flop
23 : Prakash kumar
24 : superb movie
25 : VERY GOOD
In [ ]: