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

Time:04-10

I am trying to send comment in my facebook page post using graph api. Here is my code,

    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.")

I get

Error while trying to send the comment

CodePudding user response:

You are using the wrong method to add a comment. The correct method is

graph.put_comment(object_id='post_id', message='...')

You can read more in the documentation.

Edit: the response returns you a dictionary, not JSON, so json.loads() fails. Change it to

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