Prerequisites: Facebook API Set-1, Set-2, Set-3
In this article we will be discussing 3 methods :
- put_object
- put_like
- put_comment
- put_object: Writes the mentioned object to the Facebook Social Graph connected to the given parent.
Parameters:- parent_object: A string specifying the parent of the new object. For example- Post is the parent of comment, when we want to add a new comment or when we want to add a new photo, User profile is the parent of the photo.
- connection name: A string specifying the connection or edges between the objects.
Example#1: Post a message with a link to the active user wall.
importjsonimportfacebookdefmain():token="Please replace this with "me"oryour Access Token(forPosting on your wall)\orwith PAGE Access Token(forposting on Page)"graph=facebook.GraphAPI(token)message=graph.put_object(parent_object="me",connection_name="feed",message="Hello this is a great website for various Computer Science Topics.",print(json.dumps(message, indent=4))if__name__=='__main__':main()chevron_rightfilter_none

Example#2: This example shows how to use put_object to post a comment to a POST.
importjsonimportfacebookdefmain():token="Please replace this with your PAGE ACCESS TOKEN"graph=facebook.GraphAPI(token)commenttopost=graph.put_object(parent_object="PAGEID_POSTID",connection_name="comments",message="Please share and Like the website for content on Computer Science")print(json.dumps(commenttopost, indent=4))if__name__=='__main__':main()chevron_rightfilter_none

- put_comment: This methods facilitates to write a message as comment to an object.
Parameters:- object_id: A string unique for a particular resource.
- message: A string to be posted as comment.
importjsonimportfacebookdefmain():token="Please replace this with your PAGE ACCESS TOKEN"graph=facebook.GraphAPI(token)putcomment=graph.put_comment(object_id="PAGEID_POSTID",message="This is a very good website for Computer Science Topics")print(json.dumps(putcomment, indent=4))if__name__=='__main__':main()chevron_rightfilter_none

- put_like: Add like to a given object
Parameters:
object_id: A string that is a unique id for the particular resource.importjsonimportfacebookdefmain():token="Please replace this with your PAGE ACCESS TOKEN"graph=facebook.GraphAPI(token)putlike=graph.put_like(object_id="PAGEID_POSTID")print(json.dumps(putlike, indent=4))if__name__=='__main__':main()chevron_rightfilter_none

References: https://facebook-sdk.readthedocs.io/en/latest/api.html
Recommended Posts:
- Facebook API | Set-1
- Facebook API | Set-2
- Facebook API | Set-3
- EdgeRank Algorithm - Algo behind Facebook News Feed
- Design data structures for a very large social network like Facebook or Linkedln
- How Facebook Display Ads for something you searched
- Why should you not Hack Facebook!
- Facebook News Feed Algorithm
- How to auto like all the comments on a facebook post using JavaScript ?
- The true story about Facebook's closed AI Wing
- How Did Facebook Remove 2.2 Billion Fake Accounts in the First Quarter of 2019?
- 5 Mind-Blowing Ways Facebook Uses Machine Learning
- How to Create a Facebook Phishing Page ?
- Difference between Google ads and Facebook ads
- Facebook’s TransCoder AI Converts Code Between Multiple Programming Languages
- Auto comment on a facebook post using JavaScript
- Speech Recognition in Python using Google Speech API
- Get emotions of images using Microsoft emotion API in Python
- Introduction to Postman for API Development
- Youtube Data API for handling videos | Set-1
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

