Python Forum
Delete multiple comments with a single API call (facebook)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Delete multiple comments with a single API call (facebook)
#1
Hi, currently to delete comments on posts in my facebook page I'm using the following code, which deletes one comment at a time, that is making an API call for each comment to delete.

 import facebook, requests page_id = '' post_id = '' page_token = '' graph = facebook.GraphAPI(page_token) post = graph.get_objects(ids = [page_id + '_' + post_id], fields = "comments")[page_id + '_' + post_id]['comments'] comments = post['data'] # first 25 comments while 'next' in post['paging'].keys(): # while there is a page with new comments post = requests.get(post['paging']['next']).json() # download the next page comments += post['data'] to_delete = [] for comment in comments: if (...something...): to_delete.append( comment['id'] ) for comment_id in to_delete: graph.delete_object(id = comment_id)
This require about 1 second for each comment, which can take up to hours if the comments are thousands. Is there a way to delete all the comments with a single API call? Maybe using the requests package?

It should be possible since I read it something similar in this page https://developers.facebook.com/docs/gra...h-requests
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Algorithm for extracting comments from Python source code Pavel1982 7 5,151 Aug-28-2024, 02:50 AM
Last Post: timothyferriss
  How to accept facebook cookies using python selenium? pablo86ad 0 2,041 Apr-06-2024, 09:19 PM
Last Post: pablo86ad
  Issues Scraping Facebook using facebook_scraper DustinKlent 4 6,732 Mar-19-2024, 08:17 PM
Last Post: Mostafa_heikal
  How do I add comments from a text-file to an array of folders? clausneergaard 2 3,081 Feb-08-2023, 07:45 PM
Last Post: Larz60+
  Create multiple/single csv file for each sql records mg24 6 3,716 Sep-29-2022, 08:06 AM
Last Post: buran
  Inserting line feeds and comments into a beautifulsoup string arbiel 1 2,964 Jul-20-2022, 09:05 AM
Last Post: arbiel
  Delete multiple lines from txt file Lky 6 5,241 Jul-10-2022, 12:09 PM
Last Post: jefsummers
  Reshaping a single column in to multiple column using Python sahar 7 4,574 Jun-20-2022, 12:35 PM
Last Post: deanhystad
  DELETE Post using Python FaceBook Graph API BIG_PESH 0 3,717 Mar-24-2022, 08:28 PM
Last Post: BIG_PESH
  Split single column to multiple columns SriRajesh 1 2,420 Jan-07-2022, 06:43 PM
Last Post: jefsummers

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.