Google mirror api developer zone


Published on

Google mirror api developer zone
Time to master the art of working with Google Glass
Get the glimpse of future
Lets get your hands dirty with one of the best invention of our times.
Lets rock the world with best wearable tech of our time.
Lets create some amazing experiences for all

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Google mirror api developer zone

  1. 1. Google Mirror API Developer Zone
  2. 2. API Usage Stories The Mirror API provides a set of building blocks that you can use to build services for Glass. Because Glass services are probably different than other software you have developed, it may not be obvious how to fit features of the Mirror API together. Many services fall into a few categories of API usage. Here are some stories that illustrate how to combine the features of the Mirror API to create Glass services.
  3. 3. Cat Facts Delivering content to the Glass timeline is a simple yet powerful use of the Google Mirror API. The Cat Facts sample Glassware delivers facts about cats to users and could potentially follow this flow: Your user visits your web application and subscribes by authenticating with OAuth 2.0. Every hour, on the hour, your service delivers a new Cat Fact to each of your users' Glass.
  4. 4. Timeline Items When users interact with their timeline, the main way they receive information is in the form of timeline items, otherwise known as cards. Timeline cards display content from various Glassware and swiping forward and backward on Glass reveals more cards in the past and future. You can insert, update, read, and delete timeline cards from a timeline. In addition, you can attach objects to a timeline card, such as a location or media.
  5. 5. Inserting a timeline item To insert a timeline item, POST a JSON representation of a timeline item to the REST endpoint. Note: Timeline items last for seven days on a user's Glass and are deleted from Google's servers if not updated for ten days. Most of the fields in a timeline item are optional. In its simplest form, a timeline item contains only a short text message, like in this example: TimelineItem timelineItem = new TimelineItem(); timelineItem.setText("Hello world"); service.timeline().insert(timelineItem).execute();
  6. 6. HTTP/1.1 201 Created Date: Tue, 25 Sep 2012 23:30:11 GMT Content-Type: application/json Content-Length: 303 { "kind": "glass#timelineItem", "id": "1234567890", "selfLink": "", "created": "2012-09-25T23:28:43.192Z", "updated": "2012-09-25T23:28:43.192Z", "etag": ""G5BI0RWvj-0jWdBrdWrPZV7xPKw/t25selcGS3uDEVT6FB09hAG-QQ"", "text": "Hello world" }
  7. 7. Inserting a timeline item with an attachment A picture is worth a thousand words, which is a lot more than you can fit into a timeline item. To this end, you can also attach images and video to a timeline item. Here's an example of how to insert a timeline item with a photo attachment: TimelineItem timelineItem = new TimelineItem(); timelineItem.setText("Hello world"); InputStreamContent mediaContent = new InputStreamContent(contentType, attachment); service.timeline().insert(timelineItem, mediaContent).execute();
  8. 8. Attaching video If you are attaching video files to your timeline items, we recommend that you stream the video instead of uploading the entire payload at once. The Google Mirror API supports streaming with HTTP live streaming, progressive download, and the real time streaming protocol (RTSP). RTSP is frequently blocked by firewalls, so use the other options when possible. To stream video, use the PLAY_VIDEO built-in menu item and specify the video's URL to be the menu item's payload. See Adding built-in menu items and supported media formats for more information.
  9. 9. Bundling Bundling allows you to group related but distinct items together, like for individual messages in an email thread. Bundles have a main cover card that a user taps to display a sub-timeline that contains the other cards in the bundle. Bundles are distinguished from normal timeline cards by a page curl in the upper right corner of the bundle's cover card.
  10. 10. Menu Items Delivering content is only half of the story. Most interesting services also allow users to interact with timeline cards through menu items. Menu items allow users to request actions that are related to the timeline card, and come in two types: built-in menu items and custom menu items. Built-in menu items provide access to special functionalities provided by Glass, such as reading a timeline card aloud, navigating to a location, sharing an image, or replying to a message: Custom menu items allow your application to expose behavior that is specific to your Glassware, and you can also provide a menu item icon to match your branding.
  11. 11. Defining custom menu items Built-in actions may not always be enough. Many services need to expose their own specific menu items. This is where custom actions come into play. Create a custom menu item by specifying a menuItem.action of CUSTOM and a When your user triggers one of your custom menu items, a notification is sent to your service with the populated. This allows you to determine the source of the notification. You must also populate menuItem.menuValue to specify an iconUrl and displayName that will appear on the glass device.
  12. 12. HTTP/1.1 201 Created Date: Tue, 25 Sep 2012 23:30:11 GMT Content-Type: application/json Content-Length: 303 { "text": "Hello world", "menuItems": [ { "action": "CUSTOM", "id": "complete" "values": [{ "displayName": "Complete", "iconUrl": "" }] } ] }
  13. 13. Subscriptions The Mirror API allows you to subscribe to notifications that are sent when the user takes specific actions on a Timeline Item or when the user location has been updated. When you subscribe to a notification, you provide a callback URL that processes the notification. Receiving notifications A notification from the Mirror API is sent as a POST request to the subscribed endpoint containing a JSON request body. { "collection": "timeline", "itemId": "3hidvm0xez6r8_dacdb3103b8b604_h8rpllg", "operation": "UPDATE", "userToken": "harold_penguin", "verifyToken": "random_hash_to_verify_referer", "userActions": [ { "type": "<TYPE>", "payload": "<PAYLOAD>" } ] }
  14. 14. Notification types The Mirror API sends a different notification payload for different events. Shared timeline item The user has shared a timeline item with your Glassware. { "collection": "timeline", "itemId": "3hidvm0xez6r8_dacdb3103b8b604_h8rpllg", "operation": "UPDATE", "userToken": "harold_penguin", "verifyToken": "random_hash_to_verify_referer", "userActions": [ { "type": "SHARE" } ] }
  15. 15. Reply The user has replied to your timeline item using the built-in REPLY menu item: { "collection": "timeline", "itemId": "3hidvm0xez6r8_dacdb3103b8b604_h8rpllg", "operation": "INSERT", "userToken": "harold_penguin", "verifyToken": "random_hash_to_verify_referer", "userActions": [ { "type": "REPLY" } ] }
  16. 16. Delete The user has deleted a timeline item: { "collection": "timeline", "itemId": "3hidvm0xez6r8_dacdb3103b8b604_h8rpllg", "operation": "DELETE", "userToken": "harold_penguin", "verifyToken": "random_hash_to_verify_referer", "userActions": [ { "type": "DELETE" } ] }
  17. 17. Custom menu item selected The user has selected a custom menu item set by your service: { "collection": "timeline", "itemId": "3hidvm0xez6r8_dacdb3103b8b604_h8rpllg", "operation": "UPDATE", "userToken": "harold_penguin", "userActions": [ { "type": "CUSTOM", "payload": "PING" } ] }
  18. 18. Location update A new location is available for the current user: { "collection": "locations", "itemId": "latest", "operation": "UPDATE", "userToken": "harold_penguin", "verifyToken": "random_hash_to_verify_referer" }
  19. 19. Voice command Your user has activated a voice command, for example: "Ok Glass, take a note, Cat Stream, Chipotle's birthday is tomorrow". The following notification is sent to your Glassware: { "collection": "timeline", "operation": "UPDATE", "userToken": "chipotle's_owner", "verifyToken": "mew mew mew", "itemId": "<ITEM_ID>", "userActions": [ {“type”: "LAUNCH"} ] }
  20. 20. Location You can use the Google Mirror API to observe the user's location in timeline items, request their last known location directly, and subscribe to periodic location updates. You can also deliver pre-rendered map images in timeline cards by giving the Mirror API the coordinates to draw. Note: Retrieving users' location requires the additional scope.
  21. 21. Subscribing to location updates Similar to subscribing to timeline updates, you can subscribe to location updates by subscribing to the locations collection. POST /mirror/v1/subscriptions HTTP/1.1 Authorization: Bearer {auth token} Content-Type: application/json Content-Length: {length} { "collection": "locations", "userToken": "harold_penguin", "verifyToken": "random_hash_to_verify_referer", "callbackUrl": "" }
  22. 22. <article> <figure> <img src="glass://map?w=240&h=360&marker=0;42.369590, -71.107132&marker=1;42.36254,-71.08726&polyline=;42.36254, -71.08726,42.36297,-71.09364,42.36579,-71.09208,42.3697, -71.102,42.37105,-71.10104,42.37067,-71.1001,42.36561, -71.10406,42.36838,-71.10878,42.36968,-71.10703" height="360" width="240"> </figure> <section> <div class="text-auto-size"> <p class="yellow">12 minutes to home</p><p>Medium traffic on Broadway</p> </div> </section> </article>
  23. 23. Contacts Contacts can be people or Glassware that users can share timeline items with. By default, Glassware cannot access timeline items that it did not create. Sharing to contacts allows users to share a timeline item with Glassware that did not create that timeline item. There are two ways that your Glassware can use contacts: Allow users to share your timeline items with other contacts: Add the SHARE builtin menu item to a timeline card. When users tap the share menu item, Glass displays a list of possible contacts to share with. See the menu items developer guide for more information on how to add built-in menu items. Allow users to share timeline items with your Glassware: Create a contact that represents your Glassware. When users want to share a timeline card, your contact appears as an option. You can also declare a list of acceptable MIME types so that your contact only appears for cards that you are interested in. To get notified of when users share a timeline card with your contact, you can subscribe to timeline notifications.
  24. 24. How sharing works
  25. 25. Declaring voice menu commands You can let users share timeline items with your Contact by inserting a voice command in the "OK Glass" menu. When triggered, voice commands share a timeline item with your contact that includes a transcription of your user's speech. You can declare the following voice commands for your contact: "take a note" "post an update"
  26. 26. Create a client ID and client secret First, you need to activate the Google Mirror API for your app. You can do this for your API project in the Google APIs Console. Create an API project in the Google APIs Console. Select the Services tab in your API project, and enable the Google Mirror API. Select the API Access tab in your API project, and click Create an OAuth 2.0 client ID. In the Branding Information section, provide a name for your application (e.g. "My Glass service"), and click Next. Providing a product logo is optional. In the Client ID Settings section, do the following: Select Web application for the Application type. Click the more options link next to the heading, Your site or hostname. List your hostname in the Authorized Redirect URIs and JavaScript origins fields. Click Create Client ID. In the API Access page, locate the section Client ID for Web applications and note the Client ID and Client Secret values.
  27. 27. Your Google Glass Playground Let’s Play with Future