如何使用图表 api 在我的 Facebook 页面 post 中发送评论?

How to send comment in my facebook page post using graph api?

我正在尝试使用图表 api 在我的 Facebook 页面 post 中发送评论。这是我的代码,

    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='...')

您可以在 documentation 阅读更多内容。

编辑:响应 returns 你是字典,而不是 JSON,所以 json.loads() 失败。改成

try:
    y=graph.put_object(x['post_id'], 'comments', message=msg)