Tag Archives: facebook

The Loser’s Script – How to wish facebook friends on their birthdays automagically in linux

Yes, It does what it tells it does. It may be one of the geekiest ways of wishing your friends on their birthdays. You won’t have to check every morning for people having birthdays, and go on writing on their walls. The script does it for you. And believe me, when you wish someone using a script for the first time, it feels terrible. You will start to see the fickleness, frailness of human relationships, freaks and fakes around us in a Web 2.0 world. But, if you dare to go forward and test it for yourself, scroll down to see the step-by-step instructions.

Step 1: Install cURL and Gnome-schedule

cURL is a command line tool for transferring data using various protocols. Gnome-schedule is a GUI for managing cron-jobs. Install them by running the famous command

sudo apt-get install curl gnome-schedule

Step 2: Setup a new application
Goto http://www.facebook.com/developers/ and setup a new application. Fill in all the required fields. Don’t forget to set ‘Application Type’ to ‘Desktop’. Remember the ‘Application ID’ and ‘Application secret’ given in the end of the process.

Step 3: Request an OAuth access token with the proper permissions
Facebook Graph API authorization documentation Has a detailed explanation about this. But if you are in a hurry,

  1. Enter the following URL in your browser, replacing YOUR_APPLICATION_ID with the application ID you got in the earlier step.
    https://graph.facebook.com/oauth/authorize?client_id=YOUR_APLICATION_ID&redirect_uri=http://www.facebook.com/connect/login_success.html&type=user_agent&display=popup&scope=offline_access,publish_stream,friends_birthday

  2. After a successful login and granting necessary permissions,  you will be given a verification code. Save it for later use.
  3. Enter the following URL in your browser, replacing YOUR_APPLICATION_ID with ‘Application ID’ and YOUR_API_SECRET with ‘Application secret' you got earlier, and VERIFICATION_CODE with the code you got in the previous step.
    https://graph.facebook.com/oauth/access_token?client_id=YOUR_APLICATION_ID&redirect_uri=http://www.facebook.com/connect/login_success.html&client_secret=YOUR_API_SECRET&code=VERIFICATION_CODE
  4. Now you will be given the precious ‘Access Token’. Save it somewhere

WARNING: Facebook does not recommend following this procedure and storing Access Tokens or Application secrets in desktop applications, because if somebody gets hold of that code, you are dead. I mean your facebook profile security is severely compromised and can be used in any malicious way they desire.

Step 4: Writing the script
No. Actually you just have to copy the following script I wrote and save it in a file like ‘/home/yourName/birthdayscript.sh’ after  entering THE precious access token of yours in the proper place.

#!/bin/bash

NOW=$(date +"%m/%d")

#Enter your access token below within quotations
ACCESS_TOKEN="blah-blah-blah-your-precious-access-token"

#Get the names and UIDs of your unfortunate friends born on a day like today
curl "https://api.facebook.com/method/fql.query?access_token=$ACCESS_TOKEN&query=SELECT%20first_name,uid%20from%20user%20where%20uid%20in%20(SELECT%20uid2%20from%20friend%20where%20uid1=564121985)AND%20substr(birthday_date,0,5)%20==%20'$NOW'" > birthdaywishtemp.xml

names=`sed -n -e 's/.*<first_name>\(.*\)<\/first_name>.*/\1/p' birthdaywishtemp.xml`
ids=`sed -n -e 's/.*<uid>\(.*\)<\/uid>.*/\1/p' birthdaywishtemp.xml`

F_ARRAY=( `echo ${names}` )
U_ARRAY=( `echo ${ids}` )

#Wish each of them with the same old boring message
for (( i = 0 ; i < ${#U_ARRAY[@]} ; i++ ))
do
curl 'https://graph.facebook.com/${U_ARRAY[$i]}'
curl -F 'access_token='$ACCESS_TOKEN'' \
    -F 'message=Hey, Happy Birthday...'${F_ARRAY[$i]} \
    https://graph.facebook.com/${U_ARRAY[$i]}/feed >> birthdaywishbackup.log

#Let you know the progress
echo "Wished ${F_ARRAY[$i]}" >> birthdaywishbackup.log
done

echo "Completed on $(date)" >> birthdaywishbackup.log

Now you can browse to the location where you saved the script via terminal and execute the script with the command

./birthdayscript.sh

And you can see the progress in the file birthdaywishbackup.log

Step 5: Automating the script
Yes, it is of no use if you have to run this manually each and everyday to wish somebody. So you can schedule it to run and write automagically on walls of birthday boys/gals everyday. If you are the geekiest type you can do it using a cron-job and you won’t need this tutorial anyway. But if you are interested, you can find how to do that here.
For the ordinary geek, there’s this dumb-simple GUI based tool called gnome-schedule. Run the command

gnome-schedule

in a terminal and you will be able to come up with a scheduled cron-job like the following in few easy steps.

IMPORTANT: Make sure you set a time of the day that you will keep your computer switched on, because a cron-job is not god, and doesn’t know how turn on the computer it is running, by itself :-D

It's done!!! Enjoy being a lazy, cold-hearted nerd, who has no sense of finer things in life.

UPDATE: With all the controversial comments about this post here and in Reddit, I found an article written by another one who has thought on the same lines which totally explains my idea behind this script and blog post. Read and post your comments

It Was Your Birthday? Social Media Didn’t Tell Me That! by Jason Douglas

Idiot’s two step guide for a cleaner facebook

http://bokardo.com/images/comics/facebook-01.gifYeah.. It’s coming to a crazy peak these days! How will this guy marry? How will that gal die? What Spongebob character are you? What flavor of pie are your neighbor? Do we care? It seems.. Yes. When I saw the clean, organized, pretty fb interface getting cluttered by hundreds of these crap – quizzes day by day, I sometimes wondered what’s wrong with these people. Facebook was turning into another hi5,tagged or mySpace for me.Then came…. the greasemonkey to the rescue.

  1. In Firefox  install the Greasemonkey add-on. Then you will see a small monkey face at the right bottom corner of your browser window.Unlike other firefox addons which does one particular thing, Greasemonkey extension lets you add so called ‘user scripts’ which can change behavior of a web page. In the next step we are going to try one such user script.fb2
  2. Click here to Install the Facebook Purity GreaseMonkey script. Go to facebook home and notice the difference. The script puts a little message in the top right hand corner of your page saying how many apps were blocked.

Gone are the days, that we kept blocking them and they were born next day with a different name again, again and again like a monster in a movie of the twentieth century. I have my neat facebook home page back again.

PS:

You can experiment with more and more GreaseMonkey Scripts to make your surfing easier, cleaner and effective. My favourite is IMDB pirated version. But try to avoid scripts which are not from userscripts.org.

If you are someone who is madly in love with these quizzes, I’m really sorry for killing off your enjoyment (and ultimate source of future predictions) ;-). I never thought this will make it to a new blog post, but the sad status messages, and angry blog posts like this and this,all over the web, made me do this.

If you are using Chrome instead of Firefox, try GreaseMetal

The clean facebook

Image Credit: Joshua Porter