Download Unsplash Photos to Google Drive

Unsplash is the best source for free images on the Internet. The images have the Creative Commons zero license meaning you can do anything with the photos.

This Google Script uses the Unsplash API to fetch the most recently uploaded photos and downloads them to your Google Drive. The photo details, like the height, width, creator name, full RAW link, etc. are appended to a Google Spreadsheet.

You can set this is a time-based trigger to automatically save all the new Unsplash photos in your Google Drive. Change the page parameter to download all the old pictures as well. You would however need to create your CLIENT_ID for the API call.

function getUnsplashPhotos() {
  try {
    var ss = SpreadsheetApp.getActiveSheet();

    // Fetch a maximum of 30 photos per API call
    var url = 'https://api.unsplash.com/photos/?client_id=API_CLIENT_ID&per_page=30&page=1';

    // Parse the JSON response in an Array
    var photos = JSON.parse(UrlFetchApp.fetch(url).getContentText());

    for (var p = 0; p < photos.length; p++) {
      var categories = [],
        photo = photos[p];

      for (var c = 0; c < photo.categories.length; c++) {
        categories.push(photo.categories[c].title);
      }

      var blob = UrlFetchApp.fetch(photos.urls.full).getBlob();

      var file = DriveApp.createFile(blob);

      file.setName(photos.user.name);

      var row = [
        photo.id,
        photo.created_at.substr(0, 10),
        categories.join(', '),
        photo.width,
        photo.height,
        photo.color, // Main Color Hex Mode
        photo.likes, // How popular is the photograph
        photo.user.name, // Credit the photographer
        photo.user.links.html,
        photo.urls.raw, // Full high res version URL
        photo.urls.full,
        file.getUrl(), // URL of the photo in Google Drive
      ];

      ss.appendRow(row);
    }
  } catch (f) {
    Logger.log(f.toString());
  }
}

Amit Agarwal is a web geek, solo entrepreneur and loves making things on the Internet. Google recently awarded him the Google Developer Expert and Google Cloud Champion title for his work on Google Workspace and Google Apps Script.

Awards & Recognition

Google Developer Expert

Google Developer Expert

Google awarded us the Developer Expert title recogizing our work in Workspace

ProductHunt Golden Kitty

ProductHunt Golden Kitty

Our Gmail tool won the Lifehack of the Year award at ProductHunt Golden Kitty Awards

Microsoft MVP Alumni

Microsoft MVP Alumni

Microsoft awarded us the Most Valuable Professional title for 5 years in a row

Google Cloud Champion

Google Cloud Champion

Google awarded us the Champion Innovator award for technical expertise

Want to stay up to date?
Sign up for our email newsletter.

We will never send any spam emails. Promise 🫶🏻