Monday, April 6, 2015

How to fetch Images from different Social Media Networks using their APIs using O. Auth 2.0 Protocol?

  1. First Open the Facebook graph explorer at
    We will get the web page similar to shown as below:

    2. Then, we need to click on Get Access Token button select the data that we want the users to provide us.After clicking the button ”Get Access Token”, we will get a screen similar to this and from the given options, we need to select the details that we want to fetch.
    (Screenshot on next page)

    3. After getting the access token, we can now use the filters provided on the left side as shown in the figure below. Select the details that you want. For example, in this case, we need to select the ‘albums’. In albums category, we need to select ‘photos’ field and then in ‘photos’ field, we need to select the ‘source’ field that will provide us the url of the images stored.

    4. After selecting the details, we need to press ‘submit’ button and it will make a GET request and give the data of all photos in users albums along with their source url and hence we can get the images through the json data that we get as shown in screenshot below.

Using the Facebook Graph API in python, we will get the same results as shown above. And hence, we can extract the urls of all the images from json data that we get and download the images on server. Finally, we can easily use them according to our use.

Fetching images from Dropbox using its API:

Dropbox doesn’t recommend to fetch all the folders and files in a single API call. There are two ways to fetch the images :

  1. Fetch one by one using get_file_and_metadata method:
    A simple example for fetching a file :

    #python code for fetching a file gsoc.txt and saving in gsoc.txt on local machine
    f, metadata = client.get_file_and_metadata('/gsoc.txt')
    out = open(‘gsoc.txt', 'wb')
    print metadata

    get_file_and_metadata method returns an httplib.HTTPResponse that we should .read() from to get the full response.
    See this link  for more information about this method.
  2. Search for the particular file types and then download:
    There's no method to get a recursive list of files, so you would need to use /search to find files or /delta with no cursor to get the full list of files.
    See the link for more info:

Fetching images from Google Drive:

Fetching images from Google Drive involves two steps:

  1. List all the folders and files in the directory to get the fileId and other metadata about the files.
    This step involves the use of Children:list method for getting the details and metadata of the files and folder in the particular folder or root directory.

    For example, searching for folders and files found in root directory in the image shown below:

    After the search is completed, we get result in JSON format as shown in the next image:
    More details about this method can be found at:
  2. After getting the fileID, the final step is to get the url for downloading the files and folders. The files are downloaded using the get method of Google Drive API.
    The code of downloading the files using the get method is self provided by Google at
    This makes the whole process of fetching the images more easier.

No comments:

Post a Comment

See all Posts

About Me

My photo

I am a Tech Enthusiastic and Open Source Lover.