I am trying to automate my daily task on Facebook while at very first I wanted to post a simple message on Facebook however I got this issue even I updated all the necessary permission to grant.
import os
import requests
def post_to_facebook_page(access_token, page_id, message, files=None):
api_endpoint = f'https://graph.facebook.com/{page_id}/feed'
# Data to be sent with the request
data = {
'message': message,
'access_token': access_token
}
# Send POST request with files if available
response = requests.post(api_endpoint, data=data, files=files)
# Check if the request was successful
if response.status_code == 200:
print('Post successful!')
else:
print('Error posting:', response.json())
if __name__ == "__main__":
# Facebook credentials
access_token = 'i_had_also_my_correct_API'
page_id = 'This_is_also_in_right_id'
# Message to post
message = 'Hello, world! This is a test post from Python.'
# Call the function to post to Facebook
try:
post_to_facebook_page(access_token, page_id, message)
except Exception as e:
print('An error occurred:', e)
I am expecting an error need to solved with suggestion and correction, however I also asked gpt but didn’t work out at all.
New contributor
Bimal Chhetry is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.