Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alternative method for extracting post reactions #194

Merged
merged 3 commits into from
Apr 11, 2021

Conversation

neon-ninja
Copy link
Collaborator

@neon-ninja neon-ninja commented Apr 1, 2021

This PR adds an alternative method for extracting post reactions, using m.facebook. If this fails for any reason, the existing w3 method is also attempted. Note that this seems more reliable if cookies are passed.

Test code:

posts = list(get_posts("Nintendo", pages=2, extra_info=True, cookies="cookies.txt"))
for post in posts:
  print(post["post_id"], post.get("reactions"))

Sample output:

3994908647260225 {'like': 168, 'love': 19, 'care': 4, 'angry': 3}
3994422230642200 {'like': 2200, 'love': 774, 'sad': 433, 'care': 83, 'angry': 68, 'haha': 43, 'wow': 11}
3981270225290734 {'like': 5600, 'love': 2300, 'care': 246, 'wow': 99, 'sad': 21, 'haha': 10, 'angry': 2}
3978479458903144 {'like': 216, 'love': 57, 'care': 4, 'angry': 3, 'wow': 2}
3977334782350945 {'like': 1400, 'angry': 703, 'love': 459, 'sad': 87, 'wow': 34, 'haha': 22, 'care': 18}
3968858206531936 {'like': 681, 'love': 127, 'wow': 15, 'care': 10, 'haha': 9, 'angry': 7}

@neon-ninja
Copy link
Collaborator Author

This PR has now been extended to allow for extraction of people reacting to a given post. Usage:

posts = list(get_posts(post_urls=["https://m.facebook.com/story.php?story_fbid=1931709990319458&id=285708024919671"], cookies="cookies.txt", options={"reactors":True}, timeout=15))
pprint.pprint(posts)

output:

[{'available': True,
  'comments': 0,
  'comments_full': None,
  'factcheck': None,
  'fetched_time': datetime.datetime(2021, 4, 8, 11, 15, 22, 542354),
  'image': 'https://scontent.fakl1-3.fna.fbcdn.net/v/t1.6435-9/fr/cp0/e15/q65/167519232_1931709876986136_319473773610266922_n.jpg?_nc_cat=107&ccb=1-3&_nc_sid=8024bb&efg=eyJpIjoidCJ9&_nc_ohc=_sgSzf52DosAX9ooHo2&_nc_ht=scontent.fakl1-3.fna&tp=14&oh=c61b5ffbf1ae8f595e982567c7ef67da&oe=6095C226',
  'images': ['https://scontent.fakl1-3.fna.fbcdn.net/v/t1.6435-9/fr/cp0/e15/q65/167519232_1931709876986136_319473773610266922_n.jpg?_nc_cat=107&ccb=1-3&_nc_sid=8024bb&efg=eyJpIjoidCJ9&_nc_ohc=_sgSzf52DosAX9ooHo2&_nc_ht=scontent.fakl1-3.fna&tp=14&oh=c61b5ffbf1ae8f595e982567c7ef67da&oe=6095C226'],
  'is_live': False,
  'likes': 21,
  'link': 'https://www.nintendo.com.au/the-big-multiplayer-sale?fbclid=IwAR31RzXRYSw92nc_eB3Qkz0gmg3TFfLoS1ZbP8UxX9cTLhFjRsGdp261VvE',
  'post_id': '1931709990319458',
  'post_text': 'Challenge friends and family with a selection of online '
               'multiplayer games, now up to 75% off as part of The Big '
               'Multiplayer Sale!\n'
               '\n'
               'See highlights: '
               'https://www.nintendo.com.au/the-big-multiplayer-sale',
  'post_url': 'https://facebook.com/story.php?story_fbid=1931709990319458&id=285708024919671',
  'reactions': {'like': 21, 'love': 5, 'wow': 2},
  'reactors': [{'link': 'https://facebook.com/cameron.henderson.370177?fref=pb',
                'name': 'Cameron Henderson',
                'type': 'Like'},
               {'link': 'https://facebook.com/zeusshomaly23?fref=pb',
                'name': 'Zeus Shomaly',
                'type': 'Like'},
               {'link': 'https://facebook.com/leon.walty.1?fref=pb',
                'name': 'Leroy Walty',
                'type': 'Like'},
               {'link': 'https://facebook.com/adam.sutherland.7549?fref=pb',
                'name': 'Adam Sutherland',
                'type': 'Like'},
               {'link': 'https://facebook.com/profile.php?id=100011574431906&fref=pb',
                'name': 'Jasdeep Singh Rathor',
                'type': 'Like'},
               {'link': 'https://facebook.com/nicholas.kakolyris.5?fref=pb',
                'name': 'Nicholas Kakolyris',
                'type': 'Love'},
               {'link': 'https://facebook.com/andrew.mcvicar.79?fref=pb',
                'name': 'Andrew McVicar',
                'type': 'Love'},
               {'link': 'https://facebook.com/jack.coventry.79?fref=pb',
                'name': 'Jack Coventry',
                'type': 'Like'},
               {'link': 'https://facebook.com/gail.roberts.7737?fref=pb',
                'name': 'Gail Roberts',
                'type': 'Like'},
               {'link': 'https://facebook.com/tynan.hicks?fref=pb',
                'name': 'Tynan Hicks',
                'type': 'Like'},
               {'link': 'https://facebook.com/WinderHylian?fref=pb',
                'name': 'Manuel Winder',
                'type': 'Like'},
               {'link': 'https://facebook.com/eric.apostol.3?fref=pb',
                'name': 'Eric Apostol',
                'type': 'Like'},
               {'link': 'https://facebook.com/emily.owens.737?fref=pb',
                'name': 'Emily Owens',
                'type': 'Love'},
               {'link': 'https://facebook.com/scott.gordon.56863?fref=pb',
                'name': 'Scott Gordon',
                'type': 'Like'},
               {'link': 'https://facebook.com/rodney.hockey?fref=pb',
                'name': 'Rodney Hockey',
                'type': 'Like'},
               {'link': 'https://facebook.com/Z.Landers94?fref=pb',
                'name': 'Zachary Landers',
                'type': 'Angry'},
               {'link': 'https://facebook.com/Mr.TimAir?fref=pb',
                'name': 'Jimmy Archer',
                'type': 'Like'},
               {'link': 'https://facebook.com/kaylahstreet?fref=pb',
                'name': 'Kaylah Confessore',
                'type': 'Like'},
               {'link': 'https://facebook.com/ashley.mclean.71?fref=pb',
                'name': 'Ashley Mclean',
                'type': 'Love'},
               {'link': 'https://facebook.com/profile.php?id=1018077487&fref=pb',
                'name': 'Michael Smith',
                'type': 'Like'},
               {'link': 'https://facebook.com/brandon.ladner?fref=pb',
                'name': 'Brandon Ladner',
                'type': 'Love'},
               {'link': 'https://facebook.com/jeames.granger?fref=pb',
                'name': 'Jeames Granger',
                'type': 'Wow'},
               {'link': 'https://facebook.com/dodge.jorge?fref=pb',
                'name': 'Dodge Jorge',
                'type': 'Like'},
               {'link': 'https://facebook.com/jeremiah.galawyn?fref=pb',
                'name': 'Jeremiah Alexander Galawyn',
                'type': 'Like'},
               {'link': 'https://facebook.com/TheDemons?fref=pb',
                'name': 'Giovanni Maglione',
                'type': 'Like'},
               {'link': 'https://facebook.com/pete.mcmanus2?fref=pb',
                'name': 'Pete McManus',
                'type': 'Like'},
               {'link': 'https://facebook.com/sarahrusso1410?fref=pb',
                'name': 'Sarah E. Russo',
                'type': 'Like'},
               {'link': 'https://facebook.com/tomsesselmann?fref=pb',
                'name': 'Thomas Sesselmann',
                'type': 'Wow'},
               {'link': 'https://facebook.com/rod.lord?fref=pb',
                'name': 'Rod Lord',
                'type': 'Like'}],
  'shared_post_id': None,
  'shared_post_url': None,
  'shared_text': '',
  'shared_time': None,
  'shared_user_id': None,
  'shared_username': None,
  'shares': 0,
  'text': 'Challenge friends and family with a selection of online multiplayer '
          'games, now up to 75% off as part of The Big Multiplayer Sale!\n'
          '\n'
          'See highlights: '
          'https://www.nintendo.com.au/the-big-multiplayer-sale',
  'time': datetime.datetime(2021, 4, 6, 14, 34),
  'user_id': '285708024919671',
  'username': 'Nintendo',
  'video': None,
  'video_id': None,
  'video_thumbnail': None}]

@josephbrianmnl
Copy link

Hi, this seems not to be working anymore...

@neon-ninja
Copy link
Collaborator Author

@JosephManalo please follow the issue template - #273

@josephbrianmnl
Copy link

Upon trying again, my mistake. There are no issues with this. I just forgot to put the cookies="cookies.txt" on my code,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants