IFTTT Automation: Post Instagram posts with specific hashtag to Squarespace Blog

This tutorial walks you through how to set up IFTTT and Google Scripts to automatically post an instagram photo to your Squarespace blog if you use a specific hashtag.  The hashtag trigger I set up for @pirruccello is #bpdotcom.

Initial Set Up:

  1. On Squarespace, under Blog Settings, enable post by email and record the email address provided. If you email this address it creates a new blog post.
  2. Using IFTTT, set up "New photo by you tagged" trigger for Gmail, with the hashtag you desire.  (Mine is #bpdotcom)  Set the rule to email yourself a photo email with the following body: 
    {{SourceUrl}} {{Caption}}
  3. Go to https://script.google.com and create the following script. Use your email address in place of YOUR@EMAIL.ADDRESS in the following script, and use your Squarespace Post By Email Address in place of YOURSQUARESPACE-BLOG-EMAIL@address.com:
function sendCorrectEmail() {
  var instagramThreads = GmailApp.search('from:(YOUR@EMAIL.ADDRESS) to:(YOUR@EMAIL.ADDRESS) subject:(instagram:)', 0, 25);

  for(var i = 0; i < instagramThreads.length; i++) {
    var messages = instagramThreads[i].getMessages();

    for(var j = 0; j < messages.length; j++){
      var body = messages[j].getPlainBody();
      var urlEndIndex = body.indexOf(" ");
      var url = body.substring(0, urlEndIndex);
      var content = body.substring(urlEndIndex + 1, body.length - 1);

      var newBody = "<center><img src='" + url + "' /><br /><br /><i>instagram: </i>" + content + "  </center>";

      GmailApp.sendEmail("YOURSQUARESPACE-BLOG-EMAIL@address.com", content, newBody);

  //delete all threads
  if(instagramThreads.length > 0) {

4.  In Google Scripts, click the Resources dropdown and configure a time based trigger to automatically check your email every minute.

5.  Make an Instagram post and use the hashtag you set up - within a few minutes, your post should show up (see @missmazade's cute puppy in my post below for an example of an automatic Squarespace blog post of an Instagram photo via a specific hashtag.)