Dec-04-2021, 08:33 PM
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.
It should be possible since I read it something similar in this page https://developers.facebook.com/docs/gra...h-requests
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
