Я пытаюсь отправить комментарий в своем посте на странице facebook, используя граф API. Вот мой код,
try:
x=graph.put_object(page, 'photos', message=msg, url=url) # It returns like {'id': '5887079443594804', 'post_id': '10039484545559233_588705678675675679394804'}
except:
print("Error while trying to send the midia file.")
try:
python_obj = json.loads(x)
y=graph.put_object(python_obj[post_id], 'comments', message=msg)
except:
print("Error while trying to send the comment.")
я получил
Error while trying to send the comment
Вы используете неправильный метод для добавления комментария. Правильный метод
graph.put_comment(object_id='post_id', message='...')
Вы можете прочитать больше в документация.
Обновлено: ответ возвращает вам словарь, а не JSON, поэтому json.loads()
терпит неудачу. Измените его на
try:
y=graph.put_object(x['post_id'], 'comments', message=msg)
Вы уверены, что x = graph.put_object
работает? Если вы публикуете фото, вы можете использовать graph.put_photo
graph.put_object
работает и возвращается {'id': '58874xxx6057434', 'post_id': '100394xxxx9233_5887xxxx36057434'}
x = x.replace("\'", "\"")
Эта команда не работает. у меня линукс, питон3
x=graph.put_object(page, 'photos', message=msg, url=url) print(x) z = x.replace("\'", "\"") print(z) except: print("Error while trying to send the media file.")
возвращается {'id': '588767262721988', 'post_id': '100394xxxx1559233_588767xxx721988'} Error while trying to send the media file.
Давайте продолжить обсуждение в чате.
Спасибо, мой
python_obj[post_id]
не имеет никакой ценности. У меня естьimport json
в заголовке.