So, let’s say it’s your birthday. You’re super-excited and spend the day having your cake and eating it too. The next morning you log in to Facebook, only to find your timeline completely flooded with birthday posts from all your well-wishers. You want to reply to all of them, but it would take you all day! How do you automate this whole process of liking and commenting on each birthday post without toiling away on Facebook for hours? We turn to our trusty little friend: Python!
Here are the steps to automatically reply to Facebook birthday wishes with Python:
Step 1: Create a Facebook App ID
1. Go to https://developers.facebook.com/
2. Click on “Add a New App” inside “My Apps”
3. From the window that pops up, select Website.
4. Type any name for your app. I just put in “Ashish”.
5. Click on “Create New Facebook App ID”.
6. On the new pop up box, choose any category. I selected “Education”.
7. Now click “Create App ID”.
8. Scroll to the bottom of the new page and type in any URL.
9. Hit “Next”.
Step 2: Get an Access Token
1. Scroll all the way to the top of the page and under “Tools and Support” click “Graph API Explorer”. Alternatively, you can just go to https://developers.facebook.com/tools/explorer/
2. Under “Application”, select the application you created in step 1.
3. On the dropdown menu to the right select “Get Access Token”.
4. Click on “Extended Permissions” and tick “publish_actions” and “read_stream”.
5. Now click Okay on these screens.
6. Your unique access token has appeared in the box.
WARNING: Do not give this token to anybody. It allows people to post to Facebook on your behalf.
Step 3: Set Up the Python Code
1. Download this code and save it as birthday.py
A simple script to like and comment on all posts on a user's timeline for a given day.
Useful for replying to birthday posts.
By: Ashish Acharya
# Insert your access token here. You can get a temporary one
# here: https://developers.facebook.com/tools/explorer/
access_token = 'paste your access token within these quotation marks'
# Fetch contents of your own wall by setting user to me
user = 'me'
# Set your birthday here in the same format:
birthday = '2015-06-21'
Parse date from Facebook's format to Python's datetime format.
post_date = datetime.datetime.strptime(
This function likes and comments on posts sent to it.
message = "Thank You! :)"
# convert birthday to datetime
bday = datetime.datetime.strptime(birthday, '%Y-%m-%d')
# Fetch graph, own profile and posts.
graph = facebook.GraphAPI(access_token)
profile = graph.get_object(user)
posts = graph.get_connections(profile['id'], 'feed')
# Get all posts made on your birthday from your wall.
# This code assumes they're all 'happy birthday' type posts.
birthday_posts = [
post for post in posts['data'] if parse_date(post) == bday.date()]
# Now like and comment on all birthday posts
for idx, post in enumerate(birthday_posts):
print('Post %d successfully processed.' % idx)
2. In the configuration section, add in your access code and birthday in the same format as shown.
3. Install Facebook-SDK and ‘requests’. On linux it’s as simple as
pip install facebook-sdk requests
(If you don’t have pip, you need to install python-setuptools and install it through easy_install. Just Google “install python pip”)
Step 4: Run the Code
1. Open up a terminal, navigate to the folder where you have birthday.py and run it with:
2. Relax and watch Python do some magic!
If you run into problems in any step, feel free to comment below and I’ll try my best to help you out.