- Пройдите через библиотеку Facebook:
Код: Выделить всё
import facebook
def post_to_facebook():
# Replace 'YOUR_ACCESS_TOKEN' with your actual access token
access_token = 'Acces Token'
graph = facebook.GraphAPI(access_token=access_token, version='3.0')
try:
# Upload photo or video
graph.put_object("me", "feed", message="test post", link="https://www.gainsberg.co.uk/")
print("Post successful!")
except facebook.GraphAPIError as e:
print(f"Error: {e}")
post_to_facebook()
Код: Выделить всё
Error: (#200) If posting to a group, requires app being installed in the group, and \
either publish_to_groups permission with user token, or both pages_read_engagement \
and pages_manage_posts permission with page token; If posting to a page, \
requires both pages_read_engagement and pages_manage_posts as an admin with \
sufficient administrative permission
- Процесс выполнения запроса:
Код: Выделить всё
import requests
# Your Access Keys
page_id = "61556299207020"
facebook_access_token = 'Token'
msg = 'Some message here'
post_url = f'https://graph.facebook.com/{page_id}/feed'
response = requests.post(post_url, params={'access_token': facebook_access_token, 'message': msg})
if response.status_code == 200:
print("Post successfully created!")
else:
print(f"Error creating post. Status code: {response.status_code}")
print(response.json()) # Print the error details
Код: Выделить всё
Error creating post. Status code: 400
{'error': {'message': '(#100) The global id 61556299207020 is not allowed for this call', 'type': 'OAuthException', 'code': 100, 'fbtrace_id': 'A8-v8UlMZkuEpZ6iamY0ZDn'}}
Подробнее здесь: https://stackoverflow.com/questions/779 ... automation