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
  Issues Scraping Facebook using facebook_scraper DustinKlent 4 3,547 Mar-19-2024, 08:17 PM
Last Post: Mostafa_heikal
  Algorithm for extracting comments from Python source code Pavel1982 6 414 Feb-28-2024, 09:52 PM
Last Post: Pavel1982
  How do I add comments from a text-file to an array of folders? clausneergaard 2 1,735 Feb-08-2023, 07:45 PM
Last Post: Larz60+
  Create multiple/single csv file for each sql records mg24 6 1,323 Sep-29-2022, 08:06 AM
Last Post: buran
  Inserting line feeds and comments into a beautifulsoup string arbiel 1 1,145 Jul-20-2022, 09:05 AM
Last Post: arbiel
  Delete multiple lines from txt file Lky 6 2,207 Jul-10-2022, 12:09 PM
Last Post: jefsummers
  Reshaping a single column in to multiple column using Python sahar 7 1,968 Jun-20-2022, 12:35 PM
Last Post: deanhystad
  DELETE Post using Python FaceBook Graph API BIG_PESH 0 1,423 Mar-24-2022, 08:28 PM
Last Post: BIG_PESH
  Split single column to multiple columns SriRajesh 1 1,290 Jan-07-2022, 06:43 PM
Last Post: jefsummers
  How can I assign "multiple variables" to a single "value"? Psycpus 2 1,810 Oct-04-2021, 03:29 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020