import requests
import pandas as pd
import json
page_id = "61554487605477"
post_id = "122107628540149586"
access_token = 'EAAPaIduWx3MBOwj4GBHjpt6xjMRxncIvfCYNNqlWGHDaURhZC1AeDyb3MLjNpz8WbyzyuI84nIVffDxAxnKiyPZA0PvdX45fHQkq0oXz2YI9y41SF1tI2HYDBZAD15CftytfiC9QeBb0dlZCNoDGKvSzf6CAZBnZBBxfHusaFUIeRPtPonZCUV660y0VgNwQFGnVVibWMlJMtZB99G5l5OaiXN1JbD1ySHbZAQowtiMZD' # your access token, from https://developers.facebook.com/tools/explorer/
url = f'https://graph.facebook.com/v16.0/{page_id}_{post_id}/comments?access_token={access_token}'
response = requests.request("GET", url)
# save name, time, message in excel file
data = json.loads(response.text)
# create object with only name, time, message
print(data)
def get_comment_text(comment):
return '{} '.format(comment["message"].replace("n", " "))
# Create a string containing all comments without newlines
text_data = ''.join(map(get_comment_text, data.get('data', [])))
print(text_data)
# Write the comments to a text file without newlines
with open(r'C:UsersSanathDesktopcomments_downloaderkindle.txt', 'w', encoding='utf-8') as text_file:
text_file.write(text_data)
# Display success message
print('Comments to kindle.txt')
i am trying to fetch the comments from my test facebook page by providing post and page id and access token by facebook graph api …this used to work a few months ago but now after a couple of months when i came back to run the code this is my error message
{'error': {'message': '(#200) Missing Permissions', 'type': 'OAuthException', 'code': 200, 'fbtrace_id': 'AFywRxOtJT1dOeJwznncM48'}}
Comments to kindle.txt
i want to fetch the comments and stored in a text file called kindle .
these are the permissions that i have provided in graph api:
pages_manage_cta
pages_manage_instant_articles
pages_show_list
read_page_mailboxes
pages_messaging
pages_messaging_subscriptions
page_events
pages_read_engagement
pages_manage_metadata
pages_read_user_content
pages_manage_ads
pages_manage_posts
pages_manage_engagement….
even after providing all necessary permission i am recieving a oauthexception
i have made sure that post id and page id are accurate and the access token is newly generated one