SlideShare a Scribd company logo
1 of 29
Google Mirror API

Developer Zone
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.
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.
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.
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();
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": "https://www.googleapis.com/mirror/v1/timeline/1234567890",
"created": "2012-09-25T23:28:43.192Z",
"updated": "2012-09-25T23:28:43.192Z",
"etag": ""G5BI0RWvj-0jWdBrdWrPZV7xPKw/t25selcGS3uDEVT6FB09hAG-QQ"",
"text": "Hello world"
}
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();
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.
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.
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.
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
menuItem.id.
When your user triggers one of your custom menu items, a notification is sent to your
service with the menuItem.id 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.
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": "http://example.com/icons/complete.png"
}]
}
]

}
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>"
}
]
}
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"
}
]
}
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"
}
]
}
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"
}
]
}
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"
}
]

}
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"
}
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"}
]
}
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
https://www.googleapis.com/auth/glass.location scope.
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": "https://example.com/notify/callback"
}
<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>
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.
How sharing works
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"
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.
https://developers.google.com/glass/tools-downloads/playground
Your Google Glass Playground
Let’s Play with Future

More Related Content

More from Utpal Betai

Keynote Android
Keynote Android Keynote Android
Keynote Android Utpal Betai
 
Top 10 app developer excuses
Top 10 app developer excusesTop 10 app developer excuses
Top 10 app developer excusesUtpal Betai
 
Apple design awards 2014
Apple design awards 2014Apple design awards 2014
Apple design awards 2014Utpal Betai
 
I os8 in 8 slides
I os8 in 8 slidesI os8 in 8 slides
I os8 in 8 slidesUtpal Betai
 
Mobile app for Business Success
Mobile app for Business SuccessMobile app for Business Success
Mobile app for Business SuccessUtpal Betai
 
Google Glass Development Kit - Developer Zone
Google Glass Development Kit - Developer ZoneGoogle Glass Development Kit - Developer Zone
Google Glass Development Kit - Developer ZoneUtpal Betai
 
Google mirror api
Google mirror apiGoogle mirror api
Google mirror apiUtpal Betai
 
App monetization
App monetizationApp monetization
App monetizationUtpal Betai
 

More from Utpal Betai (14)

Keynote 2017
Keynote   2017 Keynote   2017
Keynote 2017
 
Keynote Android
Keynote Android Keynote Android
Keynote Android
 
Top 10 app developer excuses
Top 10 app developer excusesTop 10 app developer excuses
Top 10 app developer excuses
 
Apple design awards 2014
Apple design awards 2014Apple design awards 2014
Apple design awards 2014
 
Appmonetization
AppmonetizationAppmonetization
Appmonetization
 
I os8 in 8 slides
I os8 in 8 slidesI os8 in 8 slides
I os8 in 8 slides
 
Eye opener
Eye openerEye opener
Eye opener
 
Mobile app for Business Success
Mobile app for Business SuccessMobile app for Business Success
Mobile app for Business Success
 
Google Glass Development Kit - Developer Zone
Google Glass Development Kit - Developer ZoneGoogle Glass Development Kit - Developer Zone
Google Glass Development Kit - Developer Zone
 
Google mirror api
Google mirror apiGoogle mirror api
Google mirror api
 
Androit kitkat
Androit kitkatAndroit kitkat
Androit kitkat
 
App monetization
App monetizationApp monetization
App monetization
 
Led money
Led moneyLed money
Led money
 
Twitter
TwitterTwitter
Twitter
 

Recently uploaded

Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon
 
Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireExakis Nelite
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsStefano
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...FIDO Alliance
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfFIDO Alliance
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024Stephen Perrenod
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaCzechDreamin
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessUXDXConf
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfFIDO Alliance
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...CzechDreamin
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctBrainSell Technologies
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?Mark Billinghurst
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsLeah Henrickson
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentationyogeshlabana357357
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform EngineeringMarcus Vechiato
 
Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Hiroshi SHIBATA
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandIES VE
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераMark Opanasiuk
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Patrick Viafore
 

Recently uploaded (20)

Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdf
 
Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - Questionnaire
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & Ireland
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 

Google mirror api developer zone

  • 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. 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.
  • 5.
  • 6. 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.
  • 7. 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();
  • 8. 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": "https://www.googleapis.com/mirror/v1/timeline/1234567890", "created": "2012-09-25T23:28:43.192Z", "updated": "2012-09-25T23:28:43.192Z", "etag": ""G5BI0RWvj-0jWdBrdWrPZV7xPKw/t25selcGS3uDEVT6FB09hAG-QQ"", "text": "Hello world" }
  • 9. 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();
  • 10. 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.
  • 11. 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.
  • 12. 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.
  • 13. 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 menuItem.id. When your user triggers one of your custom menu items, a notification is sent to your service with the menuItem.id 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.
  • 14. 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": "http://example.com/icons/complete.png" }] } ] }
  • 15. 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>" } ] }
  • 16. 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" } ] }
  • 17. 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" } ] }
  • 18. 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" } ] }
  • 19. 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" } ] }
  • 20. 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" }
  • 21. 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"} ] }
  • 22. 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 https://www.googleapis.com/auth/glass.location scope.
  • 23. 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": "https://example.com/notify/callback" }
  • 25. 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.
  • 27. 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"
  • 28. 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.