PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, November 3, 2022

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

 November 03, 2022     facebook-graph-api, python, python-3.x     No comments   

Issue

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


Solution

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)


Answered By - Abhinav Mathur
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing