tag tutorial, glass

Google Glass Hello World

You have to start somewhere. We're excited to hear what co-founder Chris Selmer learns at Google I/O, but until then let's jump right in with a basic "Hello World" example.

To deploy this example you'll need access to the Mirror API Developer Preview. If you have access, go to the Google Glass Java Quick Start page and follow the instructions for configuring your environment. If you don't have access we've included the output so you can follow along.

Timeline items, aka "cards," display information retrieved from a REST endpoint. A card is the basic unit of visual display for Glass; think of it like a simple web page. It's easy to work with timeline items because they're represented as a JSON structure.

To insert a new card, POST your JSON to the REST endpoint. You'll need to take three simple steps: create the new timeline item, set the text, and execute the command. "Hello World" in Java looks like this:

TimelineItem timelineItem = new TimelineItem();
timelineItem.setText("Hello world");
service.timeline().insert(timelineItem).execute();

Which creates the following raw HTTP:

POST /mirror/v1/timeline HTTP/1.1
Host: www.googleapis.com
Authorization: Bearer {auth token}
Content-Type: application/json
Content-Length: 26

{ "text": "Hello world" }

Glass will add the card to your timeline, and your user will see "Hello World."

Google Glass Hello World display

Ready to start your Google Glass project?

Let's talk about your project today.