Free Instagram Printer

Insta Printer

Please note this blog represents a working concept, but I cannot offer any support towards the creation of an app. Thanks for reading!

A tutorial, an app, and a cause. By Lee Martin.

A few weeks back I launched the In Rock We Trust campaign [1] for the Foo Fighters. At the end of that post, I mentioned that I wrote some software which printed the customized bills in real-time as they were minted on the site. I also mentioned that you could use a similar technique to create your own Instagram printer.

But what is an Instagram Printer?

New York based creative agency, Breakfast, pioneered this technique in a Kickstarter project they dubbed Instaprint. The basic concept was this:

Instaprint prints out Instagrams by watching out for any photos tagged with specific location or hashtags.

So, let’s say you’re throwing a Halloween party next week, and you’ve told all your friends to tag their Instagram photos #haleeween2012. You could technically set up a printer to be printing off these Instagram photos in real-time as they’re taken, effectively creating a photo booth of sorts for your friends. Pair this with a nice compact photo printer and you’re creating a keepsake for every attendee. Pretty damn cool.

The Breakfast Instaprint campaign turned out to be a bit too ambitious and their Kickstarter was unsuccessfully funded. They resorted to renting the device for around $5,000 a day, ouch. I want to make an analogy here that you could buy Instagram for $5,000 but we know that isn’t true. However, that is still quite a bit of money and out of the reach of most everyone.

So, when trying to devise a solution for the In Rock We Trust minter, I stumbled upon a technique that could easily emulate this concept with almost any printer and operating system for free. The solution I’m offering comes in two parts:

  1. An explanation: Any developer can make use of this blog post to create their own Instagram printer or any sort of API based printing application.

  2. An app: Any user can use my Insta Printer app to set up their own Instagram printer in a few minutes, but I’ll need your help to raise some limitations I’m facing. More on that later.

In the style of Jock Jams: Ya’ll ready to print?

Insta Printer Explanation

Before I get into any specifics, let’s take a look at a high level overview of how my Insta Printer app works:

Instagram > Insta Print > Cloud Print > Chrome > Printer

  1. An Instagram photo with your specified tag is taken.
  2. The Insta Printer app responds to a realtime update from Instagram and sends the photo in the form of a print job data to Google Cloud Print.
  3. Google Cloud Print creates the print job with specified media and target printer then proxies the print job over to Google Chrome.
  4. Google Chrome then sends the print job over wifi or ethernet to the printer.
  5. Finally, the printer receives the job and prints the photo.

In order for all of this to work properly, you must be signed up to and have your printers connected to Google Cloud Print and have a properly setup, logged in, and open copy of Google Chrome running.

Sending Print Jobs to the Cloud

Wait, what the hell is Cloud Print?

Google Cloud Print is an under appreciated service offered by Google that connects your printers to the web. As they put it:

Using Google Cloud Print, you can make your home and work printers available to you and anyone you choose, from the applications you use every day. Google Cloud Print works on your phone, tablet, Chromebook, PC, and any other web-connected device you want to print from.

One common misconception of Google Cloud Print is that it only works on Cloud Print enabled printers. This is false. In fact, Google Cloud Print will work with just about any Internet connected printer as long as it has a clear line of communication to an open copy of Google Chrome. Google likes to refer to these non-cloud enabled printers as Classic Printers.

Guilty as charged. Let’s set one up. [2]

Setup a Classic Printer

  1. Download and Install Google Chrome.
  2. Open Google Chrome and then the browser’s settings. ⌘+,
  3. Click the Show advanced settings link.
  4. Scroll down to the “Google Cloud Print” section. Click Sign in to Google Cloud Print.
  5. In the window that appears, sign in with your Google Account to enable the Google Cloud Print connector.
  6. When the confirmation message appears, click Finish printer registration.
  7. Google Cloud Print has been enabled.

You can test your setup from the bottom of Google’s instructions by clicking the Print a Test Page link.

API Service Interface

Google also offer developers an API to automate print job submission, and therein lies the magic of this service. All you need is a Google OAuth2 access token with the appropriate permissions.

I won’t go into details of how to obtain an access token from a Google user as this has been documented before, but in general I use omniauth-google-oauth2 with the following provider / permissions setup:

use OmniAuth::Builder do
  provider :google_oauth2, CLIENT_ID, CLIENT_SECRET, { scope: "cloudprint,userinfo.email", access_type: "offline", approval_prompt: "force" }
end

Once you have an access token, the first thing you’ll need is a printerID for the device you wish to use. The best way to obtain this is to present a list of printers on the front end so the user can choose. Here’s how to pull a list:

access_token.get("https://www.google.com/cloudprint/search")

Then, with the printerID, we can easily submit a print job:

access_token.post("https://www.google.com/cloudprint/submit", params: { printerid: PRINTER_ID, title: "Insta Print", content: PHOTO_URL, contentType: "url" })

Now that we know how to print, let’s work on obtaining what we want to print: Instagram photos.

Kicking it Real Time with Instagram

Instagram offers a real-time API based on the PubSubHubBub protocol which allows your app to subscribe to hashtags, geographies, locations, or users and be notified when any new associated photos are posted.

The only prerequisite for setting this up is registering an Instagram application. Once you have your app client key and secret, you can setup your Instagram client. I like to use the Instagram Ruby Gem to do this.

Instagram.configure do |config|
  config.client_id = CLIENT_ID
  config.client_secret = CLIENT_SECRET
end

Instagram has nice documentation on subscribing to the appropriate object and responding to the incoming updates, but here’s a very simple example of how I’m doing it with the Instagram Ruby Gem on Sinatra.

// Create a tag subscription, the callback url should accept both GET and POST requests
get '/subscribe' do
  Instagram.create_subscription("tag", CALLBACK_URL, "media", { object_id: TAG })
end

// Verify your subscription by echoing back the hub.challenge
get '/subscribe/callback' do
  request.params["hub.challenge"]
end

// Receive updates
post '/subscribe/callback' do
  Instagram.process_subscription(request.body.string) do |handler|
    // do something
  end
end

One thing to note is that the changed data, that is the actual photos, are not included in these updates. It is merely a notification of new media. I’ll explain how to fetch these new photos in the next section.

Instagram + Google Cloud Print == Magic Trick

It’s an illusion, Michael.

Now that we know how to send print jobs to Google Cloud Print and subscribe to real-time photos from Instagram, finishing our Insta Printer is easy. We simply combine the two techniques on the subscription callback method. Take a look at the code below:

post '/subscribe/callback' do
  Instagram.process_subscription(request.body.string) do |handler|
    handler.on_tag_changed do |tag|
      photos = Instagram.tag_recent_media(tag).data

      if photos.length != 0
        for photo in photos
          access_token.post("https://www.google.com/cloudprint/submit", params: { 
            printerid: PRINTER_ID, 
            title: "Insta Printer", 
            content: photo["images"]["high_resolution"]["url"], 
            contentType: "url"
          })
        end
      end
    end
  end
end
  1. Process each incoming subscription by passing the request body to a tag specific handler event.
  2. Fetch recent photos from Instagram which contain the required tag using the tag_recent_media function.
  3. If photos exist, loop through each and submit the high resolution photo url as a print job to Google Cloud Print.

Instagram will then update your app each time a new photo is posted with the subscribed tag, and your app will pass the photo’s url off to your Google Cloud printer. Hell yeh.

Insta Printer App

Insta Printer App

So that was a high level explanation of the technique I’m using. For those of you who don’t feel like programming, I’ve combined these features in a simple turn-key app called Insta Printer.

Insta Printer is an app that allows anyone with a Google account and Google Chrome to setup a printer that prints Instagram photos posted with a specific tag in real-time.

The only prerequisites for using Insta Printer is installing Google Chrome and setting up Google Cloud Print.

Instructions

Once the prereqs are met, fire up Chrome, go to Insta Printer, and do the following:

  1. Login with your Google account.
  2. Select the printer you wish to use.
  3. Choose an Instagram hash tag.

And, that’s it! You have successfully created an Instagram printer. Now all photos tagged with the tag you specified will print out on your printer.

However, there is one…

Problem

Instagram restricts all apps to only 30 real-time subscriptions at any given point. This limitation will only allow me to make this app available to 30 users at a time. Bummer. One possible solution, would be to allow each user the ability to provide their own Instagram client id and secret, but that adds another step I’d like to avoid.

So what can we do?

The Cause

We gotta take the power back!

Well, we can try to get Instagram to whitelist my app so that it doesn’t run into limitations. That way, we can all, have Instagram printers for Halloween!

By the time this blog gets out, I hope to have their attention, and you can show your support by taking an Instagram and tagging it #freeinstaprinter, tweeting, and upvoting.

If that doesn’t work out, I’ll open-source the app here as soon as I get a second to package it up for deployment.

Follow me on Twitter and I’ll let you know how that goes.

Conclusion

Is this the best way? Probably not, but I do like that it is software only. Regardless, I think this is a testament to the power of Google Cloud Print. You could use a similar technique to create a Little Printer clone and yes, even a Foo Fighters minter.

Please let me know if you have any questions or comments on Twitter or via email hi@leemartin.com.

Happy printing!


[1] Check out that campaign here and read the behind-the-code blog here.

[2] Here’s Google’s extended instructions on connecting your classic printer to Google Cloud Print.

 
357
Kudos
 
357
Kudos

Read this next

Soundication

or on converting your audio into YouTube videos When it comes to sharing music on the web, two factors are of the upmost importance: accessibility and syndication. I’ve preached a lot about making sure your content is accessible... Continue →