This is how I downloaded profile pics of my Facebook friends using Graph API

Standard

Hey there !

A few days ago, my friend Hasil wrote a python script to post “Thank you” comments on B’day posts automaticlly using Facebook Graph API. It suddenly arose my interest in Graph API. And, after having developed applications(small/mid level) based on more than 8 APIs till the moment, it was just another API that I was going to work with; But the most complicated one I have ever worked with. So let me share my experience with you all, hope you guys will enjoy it, I surely did enjoy learning and using it.

What is Graph API?

Facebook Graph API

Graph API is HTTP based API(Application Processing Interface), that allows developers to send GET and POST requests to Facebook servers for data exchanging.

HTTP is a standard web protocol that is used all over the world and most of web applications for fetching and sending data to a remote server, of which GET and POST are two defined ways to work with data.

Graph API is HTTP based and hence helps us in fetching,GET request and posting, POST request from Facebook servers really easily without going into complex process underneath and any programming language which has support for these two requests can be used. But Python is my choice of language for some obvious reasons ;)

For identifying these GET/POST requests uniquely for each developer, Facebook uses an access token and all the requests are uniquely identified by Facebook server using this token only. We will shortly get to know how to get the unique access token. So let’s get started.

Getting Acess Token:

As mentioned earlier, everytime we send request(GET/POST) to Facebook, we need to use access token for Facebook servers to identify us as a unique developer. Generating an access token is really easy. Just follow the following simple steps:

  • Open Graph API explorer and click on Graph API Explorer. Now, click on Get Access Token and tick all the options that come under your set of requirement from Graph API. (PS: you can tick all the options including the ones in Extended Permissions)
  • A really long random code will be generated and that’s our access token which is required to work with this amazing Graph API.

Fetching Details of Friends with Script:

For making HTTP requests to Facebook servers, I am going to use Python module Requests. It makes our life really easy(one of the reasons that Python is the language of my choice).

import requests
import json
token = ‘ ‘ # paste the access token that you got in last step, here.
api_url = “https://graph.facebook.com/v2.1/
params = {‘access_token’ : token}
call = “me/friends?fields=picture.width(9999).height(9999).type(large),gender,name”
response = requests.get(api_url + call, params=params)
r = (json.loads(response.content))

And the output will be some JSON encoded object returning the information about your friends. Now you just need to read the JSON object and use information about each of your friends one by one.

Downloading Profile Pictures from the information extracted:

Now, that we have extracted all the information about friends, next job will be to perform download action on profile picture of everyone. Just create a folder in the main directory where your python script is saved, named ‘images’.

import urllib2
for f in r['data']:
p_url = str(f['picture']['data']['url'])
urlopener1 = urllib2.build_opener()
page1 = opener1.open(p_url)
my_picture = page1.read()filename = f['name']+”_”+f['id']+”.jpg”
print filename+” downloaded…”
fout = open(‘images/’+filename, “wb”)
fout.write(my_picture)
fout.close()

Now you can check your images folder. It will have all the downloaded profile pictures of your friends.

http://www.youtube.com/watch?v=yPjBgOw_Pc4

That’s it. It may seem to be complicated at first, but you can open Graph API explorer at any point of time and understand how things are working.

Here is the Github Repo where I have committed the entire code that I used to download profile pics of my facebook friends. You can fork it and play around it as you want.

For feedback/suggestions/feature-requests, tweet me @sahildua2305 #FBtrick

How I developed my most-famous self-project in just 3 hours!!!

Standard

How I developed my most-famous self-project in just 3 hours!!!

I am going to write about my journey to develop my most-famous self-project — MySpeed Application.

MySpeed Application

Here’s how I started writing code that night —

On a crazy night, I was being extra-innovative and mad for developing something cool. I was searching APIs to use and create something awesome and innovative out of them. Suddenly I thought about how the internet speed testing websites work and became curious in running internet speed tests via API. I started searching for Internet Speed Testing API. I found a couple of them but which were completely redundant.

Finally, I came across this one which made my night! SpeedOf.Me They are the only service providers which provide internet speed testing services without any adobe flash(completely HTML5). They had their API in JavaScript language only(which isn’t generally my stronger part). But I was fascinated enough by the API scope that I was compelled to develop a web-app surrounding the API.

I, actually started coding at 2:10 am, 31st July. Starting from the basic rest running script to the pre-final draft of the web-app that had just a couple of HTML elements(a couple of tables and some chunk of text).

What did I want to make—

By this time, I had entire idea of what I wanted to make. I wanted to develop an app that will let users run internet speed tests, find out their download & upload speeds and the most importantly — will tell them their global rank based on previous results.

What I ended up developing—

After coding continuously for about 3 hours – at 5:00 am, I was ready with the Beta version of the app. I thought a little about the name, and decided to name it MySpeed Application.

By that time, I was already running late. But I needed a lot of people to test the app that I had created just out of my curiosity. So, that was the time to act a little bit devil! I mailed the link with description of the application to the mail list of PicsMashup. Acting a little smarter, I scheduled the mails to go at 12:15 am — just to make sure it reach out to maximum people. But, all in vain! Not even a single person opened the email(except me of course). But, I knew it was the fault of the title that I chose for the email not the application itself. So, to attract people to validate the idea and test the beta application, I shared it with all of my social networks and sat back calmly to see results. The results were astonishing. I got more than 80 unique(IP) users within next 24 hours. Nonetheless, 400+ visitors!

Current Scenario—

Till the moment of writing this article, MySpeed Application has got more than 150+ unique testers and 1.5k+ visits on the web-app. I keep on improving it and adding new features to the app as much as I can get time from my super-tight schedule.

For feedback/suggestions/feature-requests, tweet me @sahildua2305#MySpeed

Node.js: does it have any future?

Standard

Originally posted on Altabel Group's Blog:

Within a short period of time since its initial release in late 2009, Node.js has gained the interest of thousands of experienced developers, grown a package manager and a corpus of interesting modules and applications, and even became the reason for a number of startups to appear. You may have heard about node.js, or read articles claiming how great it is; you may have even read some technically focused explanations on why it is so good.

So let’s try to understand what it is about this technology that makes it interesting to developers. And what the commercial pluses of adopting Node.js when developing and deploying web applications.

I’ve carefully look through a number of forums and experts’ opinions in these regards. Below you could find some main reason why it is worth to use Node.js.

* Node.js is a platform for writing high-performance, scalable web applications and network programs in…

View original 514 more words

Glorious Success

Standard

It was Matric Examination Results (PSEB), 2009. One day before the announcement of results, in the early morning, my father asked-“beta kya hone waala hai kal?? merit list (Top 1%)  mein aa toh jaayega naa??“. I had no answer, just nodded with a silence. Mom & Dad then got to go to some relatives. My younger brother & me were alone at home.

In the afternoon, door-bell rang!! I opened the door, and what i saw was a completely unknown person to me, rushing happily into the house. Before I could ask him anything, he congratulated me introduced himself as a Press Reporter from daily newspaper Dainik Jagran” and asked me to ask my father to come. I had no idea whats going on. I told him that Mom & Dad werent at home. Seeing my totally confused face, he started speaking and thereby making me more & more confused!!

He said-“teri punjab mein first position aayi hai!!!!!” I was like “ye banda pagal ho gya h kya!! ya fir galat address pe aa gya hai!!”. I wasnt ready to believe what he was saying. But finally he convinced me that I was the person securing Rank#1 in Punjab. I was in a condition like “tum kon ho aur main kon hu aur kahaan huu main abhi :P “. Then he called my Dad to tell him the good news. He was overjoyed as expected. Mom-Dad headed to home as quickly as possible with just a little bit of sweets because even they were not confident about that news.

For the first time in my life, I felt that my parents were happy because of me. This made my success even more enjoyable and proudy one too ;) . Then there was my first interview. After that it was like “one goes, other comes”. There were several interviews of mine & my parents.

Here are some pics of those wonderful moments when i was rewarded for my “glorious success”…….

100_2735DSC_0039

2 Years Spent in Chandigarh- The City Beautiful

Standard

I am from Tanda Urmar, Punjab. After having my matric standard education in 2009 in a local school there, it was time to head towards IIT & AIEEE preparations. Due to some delay in decision regarding this, I began my competitive preparation at FIITJEE, Chandigarh centre in 2010. There I joined week-end program so as to keep my 12th studies at par with that of competitive study. I used to go to Chandigarh every Saturday early morning and then return on Sunday evening. Yeah, it was a very hectic and boring schedule.

But the only thing that was fascinating me during that time interval was Chandigarh City! Chandigarh’ Open Roads! Chandigarh’s Beauty! Chandigarh’s Open Minded People! Those OTDIs running endlessly on those open roads! That staring at attractive Girls! It was an endless Attraction!!! <3 <3 (still under its influence :P)

Coming to study part which was my aim behind coming Chandigarh- in earlier days I was not able to understand even a single thing that teachers used to narrate in the class. But it didnt take me much time to come into my own colors! In the meanwhile, I got some new friends as expected.

  • Bharat Bajaj- got selected in IIT with AIR 1073. Doing chemical engg. at IIT Delhi.
  • Ankit- got AIR 12000 in AIEEE. Doing CSE at NIT Kurukshetra
  • Hasil Sharma- got 308 in BITSAT. Doing chem. engg. at BITS Pilani.

And now its my turn to declare what did i get!!

Results didnt go in my favour!! I was thrown completely out of track!!

I didnt get selected for IIT. In AIEEE too, I was unable to justify my talent that had made me Punjab Board State Topper once in Matric Standard!

Then the biggest question was what to do now? The options available with me were- either to take admission in a low standard college or to put a break and prepare for IIT again!

And obviously the decision was very tough! Some of my Father’s friends advised him not to let me drop a year. Yes, It was risky- Infact very risky! But I was not in mood of joining the college that I deserved at that time. I got struck to my decision of preparing for IIT again!! And my father too agreed with me!! I joined AAKASH Institute, Chandigarh centre.

This was the turning point in my life. I had to go to Chandigarh again, but this time with some strong determination. I wanted to prove those relatives and my father’s friends wrong who had scolded them for the decision of Drop! There I started my preparations at the speed of light and decided to continue at the same pace throughout the year. Soon I was An Apple Of my teachers Eyes! In the meanwhile I got a few new friends- Mani, Sarbjeet, Dilsher, Mehak, Tamanna, Komal & some hostelers- Aakash, Manpreet, Aarush, Devan, Ishaan &  few more…..

Throughout the year, I studied and for the first time in my life enjoyed studying!! In hostel we had many occasional parties too. We had alot of fun & mastii meanwhile!!!

The whole year went well. Finally it was time of Exam- the long awaited moment! It was 8th April, 2012. But unfortunately it was not my day again! I made a lot of mistakes and after the exam I could easily find out that the only hope i had was AIEEE. Then i put even more efforts in its preparation. This time I made it!!!! Exam went enough good that i was able to see a clear future through thick forests!!

After results the value of a year dropped came out to be AIR IIT-5408 & AIR AIEEE 3128. It made my way clear to Punjab’s best engineering college- PEC, Chandigarh. But then I came to know about some more colleges that were in my easy reach with a brilliant rank in AIEEE including DTU, NIT Allahabad, NIT jaipur, IIIT heydrabad & NSIT. During this, I was offered Mining Engineering at IIT-BHU. I declined the offer! Then the only thing I had to do was to wait for the conselling results. I wanted to join a good college in Delhi. But my parents wanted me to join PEC. I remember exactly that it was 29th july 2012, when counselling results for PEC were announced. And I got CSE there. I went there acc. to parents wish and made registration and did other official formalities. But it was decided that if ever I get a chance to join DTU or NSIT, I would withdraw my admission at PEC. And luckily that day was 31th July 2012. Yes, just two days later my wish came true! then there was literally nothing more to think about. I packed my luggage, got my documents ready & headed to Delhi.

And here it comes, finally I was in My Dream City- DELHI….. btw i m still here. enough for now. will share further experiences later.