Getting Started With Google Glass Development Using Ruby, the Mirror API and Heroku

While Google Glass is a Android device, you don’t need to be an Android developer to start to create apps for it.

What is the Mirror API

The Mirror API is a Google API based cloud service that hooks into a Glass device using Oauth to sync via the users Google account. Since this Google account is needed to set up glass, users can grant permission to a app via a Oauth sign in and then behind the scenes the api is used to add cards to their timeline, get location updates etc..

Getting Started

To get started you will need to set up a google developers account if you don’t already have one and then login to the Google APIs Console here. Once you are in the console you should see a screen that looks something like this.
Screen Shot 2014-06-01 at 10.04.37 PM
Click “Create Project” to create a new project.
Screen Shot 2014-06-01 at 10.07.16 PM
Now you will be in a screen that looks something like this.
Screen Shot 2014-06-01 at 10.08.59 PM
Now Click on “APIs & Auth”, make sure that “APIs” is selected and scroll down to “Google Mirror API” and toggle it on.
Screen Shot 2014-06-01 at 10.13.17 PM
Now go to credentials and click “Create new Client ID”.
Screen Shot 2014-06-01 at 10.17.58 PM
You will want to choose a web application. For “Authorized Javascript Origins” you will want to enter any servers you are going to use. While working on this sample app I used http://localhost and https://my-app.herokuapp.com. For the “Authorized Redirect URI” you will want to have your Oauth callback endpoint. In my case they were http://localhost/oauth2callback and https://my-app.herokuapp.com/oauth2callback.
Screen Shot 2014-06-01 at 10.28.30 PM
Now you will want to clone the mirror-quickstart-ruby project from my Github repo here. Google offically deprecated their example and it was missing a couple of important things for people to get up to speed quickly. I updated the example to make it easy to deploy onto Heroku by adding in Active Record and Postgres support.

Running locally

In order to run this locally you will need to have Postgres installed. You will also need to set the following environment variables:

export PG_USER=<your Postgres UserID>
export PG_PASS=<your Postgres Password>
export PG_PORT=<your Postgres port>
export RACK_HTTP=http

Next you will need to update the client_secrets.json file with the Client ID and Client Secret from the credentials option under the “APIs & auth” and “Credentails” tab in the developers console.
Screen Shot 2014-06-01 at 10.46.19 PM

{
    "web": {
        "client_id": "your client id",
        "client_secret": "your client secret",
        "redirect_uris": [
            "http://localhost:9292/oauth2callback"
        ],
        "auth_uri": "https://accounts.google.com/o/oauth2/auth",
        "token_uri": "https://accounts.google.com/o/oauth2/token"
    }
}

Then all that you need to do is to install the gems, start the app and hit it with your browser.

bundle install
rackup

Running on Heroku

Some Mirror API features such as subscribing to location updates require a https endpoint with a verified certificate. Heroku automatically gives you a verified https endpoint when you use the default https://you_app.herokuapp.com address. To run the app on Heroku you will need to make a couple of small changes. Once you have your Heroku app created you will need to set the following environment variable on the dyno using this command.

heroku config:set RACK_HTTP=https

You will also need to modify the client_secrets.json so that your redirect_uris has only the https endpoint for your heroku app.

{
    "web": {
        "client_id": "your client id",
        "client_secret": "your client secret",
        "redirect_uris": [
            "https://<your-app>.herokuapp.com/oauth2callback"
        ],
        "auth_uri": "https://accounts.google.com/o/oauth2/auth",
        "token_uri": "https://accounts.google.com/o/oauth2/token"
    }
}

Now push the app up to Heroku and if all works correctly you should see a prompt to authenticate in using Oauth and can then add, delete, follow your location etc..

Next Steps

If you are a regular Rails user it should be pretty easy to integrate into your app. You also might want to use one of the other off the shelf Gems for Oauth etc. Applying erb templates to the cards etc would also be handy and there are a lot of boiler plate things that would be great to have in a Gem. While the Mirror API is not as fully featured as programming directly with the GDK it makes certain apps that require notifications really easy to develop. To explore it in more detail have a look at the documents here.

About Me: I am a Atlanta based, mobile/Android/IOS/AngularJS/Ruby developer, polyglot programmer, founder of Polyglot Programming Inc., wearable technology enthusiast and am interested in the internet of things. You will often find me purr programming and I regularly speak at conferences around the world. I am available for hire! More Posts

Follow Me:
TwitterLinkedInGoogle Plus

I am a Atlanta based, mobile/Android/IOS/AngularJS/Ruby developer, polyglot programmer, founder of Polyglot Programming Inc., wearable technology enthusiast and am interested in the internet of things. You will often find me purr programming and I regularly speak at conferences around the world. I am available for hire!

Posted in Development, Glass, Mobile, rails, ruby, Wearables Tagged with: , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*