Requires authorization
Inserts a new item into the timeline. See an example.
This method supports an /upload URI and accepts uploaded media with the following characteristics:
- Maximum file size: 10MB
- Accepted Media MIME types:
image/*
,audio/*
,video/*
If provided, the uploaded media is inserted as an attachment to the timeline item.
Request
HTTP request
This method provides media upload functionality through two separate URIs. For more details, see the document on media upload.
- Upload URI, for media upload requests:
POST https://www.googleapis.com/upload/mirror/v1/timeline
- Metadata URI, for metadata-only requests:
POST https://www.googleapis.com/mirror/v1/timeline
Parameters
Parameter name | Value | Description |
---|---|---|
Required query parameters | ||
uploadType |
string |
The type of upload request to the /upload URI.
Acceptable values are:
|
Authorization
This request requires authorization with at least one of the following scopes (read more about authentication and authorization).
Scope |
---|
https://www.googleapis.com/auth/glass.timeline |
https://www.googleapis.com/auth/glass.location |
Request body
In the request body, supply a Timeline resource with the following properties as the metadata. For more information, see the document on media upload.
Property name | Value | Description | Notes |
---|---|---|---|
Optional Properties | |||
bundleId |
string |
The bundle ID for this item. Services can specify a bundleId to group many items together. They appear under a single top-level item on the device. | writable |
canonicalUrl |
string |
A canonical URL pointing to the canonical/high quality version of the data represented by the timeline item. | writable |
creator |
nested object |
The user or group that created this item. | writable |
displayTime |
datetime |
The time that should be displayed when this item is viewed in the timeline, formatted according to RFC 3339. This user's timeline is sorted chronologically on display time, so this will also determine where the item is displayed in the timeline. If not set by the service, the display time defaults to the updated time. |
writable |
html |
string |
HTML content for this item. If both text and html are provided for an item, the html will be rendered in the timeline. Allowed HTML elements - You can use these elements in your timeline cards.
Blocked HTML elements: These elements and their contents are removed from HTML payloads.
Other elements: Any elements that aren't listed are removed, but their contents are preserved. |
writable |
isBundleCover |
boolean |
Whether this item is a bundle cover. If an item is marked as a bundle cover, it will be the entry point to the bundle of items that have the same bundleId as that item. It will be shown only on the main timeline — not within the opened bundle.On the main timeline, items that are shown are:
|
writable |
location |
nested object |
The geographic location associated with this item. | writable |
menuItems[] |
list |
A list of menu items that will be presented to the user when this item is selected in the timeline. | writable |
menuItems[].action |
string |
Controls the behavior when the user picks the menu option. Allowed values are:
|
writable |
menuItems[].id |
string |
The ID for this menu item. This is generated by the application and is treated as an opaque token. | writable |
menuItems[].payload |
string |
A generic payload whose meaning changes depending on this MenuItem's action.
|
writable |
menuItems[].removeWhenSelected |
boolean |
If set to true on a CUSTOM menu item, that item will be removed from the menu after it is selected. |
writable |
menuItems[].values[] |
list |
For CUSTOM items, a list of values controlling the appearance of the menu item in each of its states. A value for the DEFAULT state must be provided. If the PENDING or CONFIRMED states are missing, they will not be shown. |
writable |
menuItems[].values[].displayName |
string |
The name to display for the menu item. If you specify this property for a built-in menu item, the default contextual voice command for that menu item is not shown. | writable |
menuItems[].values[].iconUrl |
string |
URL of an icon to display with the menu item. | writable |
menuItems[].values[].state |
string |
The state that this value applies to. Allowed values are:
|
writable |
notification |
nested object |
Controls how notifications for this item are presented on the device. If this is missing, no notification will be generated. | writable |
notification.deliveryTime |
datetime |
The time at which the notification should be delivered. | writable |
notification.level |
string |
Describes how important the notification is. Allowed values are:
|
writable |
recipients[] |
list |
A list of users or groups that this item has been shared with. | writable |
sourceItemId |
string |
Opaque string you can use to map a timeline item to data in your own service. | writable |
speakableText |
string |
The speakable version of the content of this item. Along with the READ_ALOUD menu item, use this field to provide text that would be clearer when read aloud, or to provide extended information to what is displayed visually on Glass.Glassware should also specify the speakableType field, which will be spoken before this text in cases where the additional context is useful, for example when the user requests that the item be read aloud following a notification. |
writable |
speakableType |
string |
A speakable description of the type of this item. This will be announced to the user prior to reading the content of the item in cases where the additional context is useful, for example when the user requests that the item be read aloud following a notification. This should be a short, simple noun phrase such as "Email", "Text message", or "Daily Planet News Update". Glassware are encouraged to populate this field for every timeline item, even if the item does not contain speakableText or text so that the user can learn the type of the item without looking at the screen. |
writable |
text |
string |
Text content of this item. | writable |
title |
string |
The title of this item. | writable |
Response
If successful, this method returns a Timeline resource in the response body.
Examples
Note: The code examples available for this method do not represent all supported programming languages (see the client libraries page for a list of supported languages).
Java
Uses the Java client library.
import com.google.api.client.http.InputStreamContent; import com.google.api.services.mirror.Mirror; import com.google.api.services.mirror.model.NotificationConfig; import com.google.api.services.mirror.model.TimelineItem; import java.io.IOException; import java.io.InputStream; public class MyClass { // ... /** * Insert a new timeline item in the user's glass with an optional * notification and attachment. * * @param service Authorized Mirror service. * @param text timeline item's text. * @param contentType Optional attachment's content type (supported content * types are "image/*", "video/*" and "audio/*"). * @param attachment Optional attachment stream. * @param notificationLevel Optional notification level, supported values are * {@code null} and "AUDIO_ONLY". * @return Inserted timeline item on success, {@code null} otherwise. */ public static TimelineItem insertTimelineItem(Mirror service, String text, String contentType, InputStream attachment, String notificationLevel) { TimelineItem timelineItem = new TimelineItem(); timelineItem.setText(text); if (notificationLevel != null && notificationLevel.length() > 0) { timelineItem.setNotification(new NotificationConfig().setLevel(notificationLevel)); } try { if (contentType != null && contentType.length() > 0 && attachment != null) { // Insert both metadata and attachment. InputStreamContent mediaContent = new InputStreamContent(contentType, attachment); return service.timeline().insert(timelineItem, mediaContent).execute(); } else { // Insert metadata only. return service.timeline().insert(timelineItem).execute(); } } catch (IOException e) { System.err.println("An error occurred: " + e); return null; } } // ... }
.NET
Uses the .NET client library.
using System; using System.IO; using Google.Apis.Mirror.v1; using Google.Apis.Mirror.v1.Data; public class MyClass { // ... /// <summary> /// Insert a new timeline item in the user's glass with an optional /// notification and attachment. /// </summary> /// <param name='service'>Authorized Mirror service.</param> /// <param name='text'>Timeline Item's text.</param> /// <param name='contentType'> /// Optional attachment's content type (supported content types are /// "image/*", "video/*" and "audio/*"). /// </param> /// <param name='attachment'>Optional attachment stream</param> /// <param name='notificationLevel'> /// Optional notification level, supported values are null and /// "AUDIO_ONLY". /// </param> /// <returns> /// Inserted timeline item on success, null otherwise. /// </returns> public static TimelineItem InsertTimelineItem(MirrorService service, String text, String contentType, Stream attachment, String notificationLevel) { TimelineItem timelineItem = new TimelineItem(); timelineItem.Text = text; if (!String.IsNullOrEmpty(notificationLevel)) { timelineItem.Notification = new NotificationConfig() { Level = notificationLevel }; } try { if (!String.IsNullOrEmpty(contentType) && attachment != null) { // Insert both metadata and media. TimelineResource.InsertMediaUpload request = service.Timeline.Insert( timelineItem, attachment, contentType); request.Upload(); return request.ResponseBody; } else { // Insert metadata only. return service.Timeline.Insert(timelineItem).Fetch(); } } catch (Exception e) { Console.WriteLine("An error occurred: " + e.Message); return null; } } // ... }
PHP
Uses the PHP client library.
/** * Insert a new timeline item in the user's glass with an optional * notification and attachment. * * @param Google_MirrorService $service Authorized Mirror service. * @param string $text timeline item's text. * @param string $contentType Optional attachment's content type (supported * content types are "image/*", "video/*" * and "audio/*"). * @param string $attachment Optional attachment content. * @param string $notificationLevel Optional notification level, * supported values are {@code null} * and "AUDIO_ONLY". * @return Google_TimelineItem Inserted timeline item on success, otherwise. */ function insertTimelineItem($service, $text, $contentType, $attachment, $notificationLevel) { try { $timelineItem = new Google_TimelineItem(); $timelineItem->setText($text); if ($notificationlevel != null) { $notification = new Google_NotificationConfig(); $notification->setLevel($notificationLevel); $timelineItem->setNotification($notification); } $optParams = array(); if ($contentType != null && $attachment != null) { $optParams['data'] = $attachment; $optParams['mimeType'] = $contentType; } return $service->timeline->insert($timelineItem, $optParams); } catch (Exception $e) { print 'An error occurred: ' . $e->getMessage(); return null; } }
Python
Uses the Python client library.
import io from apiclient import errors from apiclient.http import MediaIoBaseUpload # ... def insert_timeline_item(service, text, content_type=None, attachment=None, notification_level=None): """Insert a new timeline item in the user's glass. Args: service: Authorized Mirror service. text: timeline item's text. content_type: Optional attachment's content type (supported content types are 'image/*', 'video/*' and 'audio/*'). attachment: Optional attachment as data string. notification_level: Optional notification level, supported values are None and 'AUDIO_ONLY'. Returns: Inserted timeline item on success, None otherwise. """ timeline_item = {'text': text} media_body = None if notification_level: timeline_item['notification'] = {'level': notification_level} if content_type and attachment: media_body = MediaIoBaseUpload( io.BytesIO(attachment), mimetype=content_type, resumable=True) try: return service.timeline().insert( body=timeline_item, media_body=media_body).execute() except errors.HttpError, error: print 'An error occurred: %s' % error
Ruby
Uses the Ruby client library.
## # Insert a new Timeline Item in the user's glass. # # @param [Google::APIClient] client # Authorized client instance. # @param [String] text # Timeline item's text. # @param [String] content_type # Optional attachment's content type (supported content types are 'image/*', # 'video/*' and 'audio/*'). # @param [String] filename # Optional attachment's filename. # @param [String] notification_level # Optional notification level, supported values are nil and 'AUDIO_ONLY'. # @return [Google::APIClient::Schema::Mirror::V1::TimelineItem] # Timeline item instance if successful, nil otherwise. def insert_timeline_item(client, text, content_type, filename, notification_level) mirror = client.discovered_api('mirror', 'v1') timeline_item = mirror.timeline.insert.request_schema.new({ 'text' => text }) if notification_level timeline_item.notification = { 'level' => notification_level } end result = nil if filename media = Google::APIClient::UploadIO.new(filename, content_type) result = client.execute( :api_method => mirror.timeline.insert, :body_object => timeline_item, :media => media, :parameters => { 'uploadType' => 'multipart', 'alt' => 'json'}) else result = client.execute( :api_method => mirror.timeline.insert, :body_object => timeline_item) end if result.success? return result.data else puts "An error occurred: #{result.data['error']['message']}" end end
Go
Uses the Go client library.
import ( "code.google.com/p/google-api-go-client/mirror/v1" "fmt" "io" ) // InsertTimelineItem inserts a new timeline item in the user's glass with an // optional notification and attachment. func InsertTimelineItem(g *mirror.Service, text string, attachment io.Reader, notificationLevel string) (*mirror.TimelineItem, error) { t := &mirror.TimelineItem{Text: text} if notificationLevel != "" { t.Notification = &mirror.NotificationConfig{Level: notificationLevel} } req := g.Timeline.Insert(t) if attachment != nil { // Add attachment to the timeline item. req.Media(attachment) } r, err := req.Do() if err != nil { fmt.Printf("An error occurred: %v\n", err) return nil, err } return r, nil }
Raw HTTP
Does not use a client library.
## A very simple timeline item 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" } ## A more complete timeline item with an attachment POST /mirror/v1/timeline HTTP/1.1 Host: www.googleapis.com Authorization: Bearer auth token Content-Type: multipart/related; boundary="mymultipartboundary" Content-Length: length --mymultipartboundary Content-Type: application/json; charset=UTF-8 { "text": "Hello world", "menuItems": [ { "action": "REPLY" }, { "action": "CUSTOM", "id": "complete" "values": [{ "displayName": "Complete", "iconUrl": "http://example.com/icons/complete.png" }] } } --mymultipartboundary Content-Type: image/jpeg Content-Transfer-Encoding: binary binary image data --mymultipartboundary--