Timeline: update

Autorisierung erforderlich

Aktualisiert ein Zeitachsenelement. Beispiel

Diese Methode unterstützt einen /upload-URI und akzeptiert hochgeladene Medien mit den folgenden Eigenschaften:

  • Maximale Dateigröße: 10 MB
  • Zulässige Media-MIME-Typen: audio/* , image/* , video/*

Anfragen

HTTP-Anfrage

Diese Methode bietet Funktionen zum Hochladen von Medien über zwei separate URIs. Weitere Informationen finden Sie im Dokument zum Medienupload.

  • Upload-URI für Anfragen für Medienuploads:
    PUT https://www.googleapis.com/upload/mirror/v1/timeline/id
  • Metadaten-URI für Anfragen, die nur Metadaten enthalten:
    PUT https://www.googleapis.com/mirror/v1/timeline/id

Parameter

Parametername Wert Beschreibung
Pfadparameter
id string Die ID des Zeitachsenelements.
Erforderliche Suchparameter
uploadType string Die Art der Uploadanfrage an den URI /upload. Zulässige Werte:
  • media: Einfacher Upload. Nur die Medien ohne Metadaten hochladen
  • multipart: Mehrteiliger Upload. Laden Sie Medien und Metadaten in einer einzigen Anfrage hoch.
  • resumable: Fortsetzbarer Upload. Laden Sie die Datei fort. Verwenden Sie dazu eine Reihe von mindestens zwei Anfragen, wobei die erste Anfrage die Metadaten enthält.

Autorisierung

Diese Anfrage benötigt eine Autorisierung mit mindestens einem der folgenden Bereiche (weitere Informationen zu Authentifizierung und Autorisierung).

Umfang
https://www.googleapis.com/auth/glass.timeline
https://www.googleapis.com/auth/glass.location

Anfragetext

Geben Sie im Anfragetext eine Zeitachsenressource mit den folgenden Attributen als Metadaten an. Weitere Informationen finden Sie im Dokument zum Medienupload.

Attributname Wert Beschreibung Hinweise
Optionale Attribute
bundleId string Die Bundle-ID für diesen Artikel. Dienste können eine Bundle-ID angeben, um mehrere Elemente zu gruppieren. Sie werden unter einem einzelnen Element der obersten Ebene auf dem Gerät angezeigt. Bearbeitbar
canonicalUrl string Eine kanonische URL, die auf die kanonische/hochwertige Version der durch das Zeitachsenelement dargestellten Daten verweist. Bearbeitbar
creator nested object Der Nutzer oder die Gruppe, der bzw. die dieses Element erstellt hat. Bearbeitbar
displayTime datetime Die Zeit, die angezeigt werden soll, wenn dieses Element auf der Zeitachse angezeigt wird, formatiert gemäß RFC 3339. Die Zeitachse dieses Nutzers wird chronologisch nach der Anzeigezeit sortiert. Dadurch wird auch bestimmt, wo das Element in der Zeitachse angezeigt wird. Wenn dies nicht vom Dienst festgelegt ist, wird standardmäßig updated verwendet. Bearbeitbar
html string HTML-Inhalt für dieses Element. Wenn sowohl text als auch html für ein Element angegeben werden, wird das html in der Zeitachse gerendert.

Zulässige HTML-Elemente: Diese Elemente können auf den Zeitachsenkarten verwendet werden.

  • Überschriften: h1, h2, h3, h4, h5, h6
  • Bilder: img
  • Listen: li, ol, ul
  • HTML5-Semantik: article, aside, details, figure, figcaption, footer, header, nav, section, summary, time
  • Strukturell: blockquote, br, div, hr, p, span
  • Stil: b, big, center, em, i, u, s, small, strike, strong, style, sub, sup
  • Tabellen: table, tbody, td, tfoot, th, thead, tr

Blockierte HTML-Elemente: Diese Elemente und ihre Inhalte werden aus HTML-Nutzlasten entfernt.

  • Dokumentheader: head, title
  • Einbettungen: audio, embed, object, source, video
  • Rahmen: frame, frameset
  • Skripterstellung: applet, script

Andere Elemente: Alle nicht aufgeführten Elemente werden entfernt, ihr Inhalt bleibt jedoch erhalten.

Bearbeitbar
isBundleCover boolean Gibt an, ob es sich bei diesem Artikel um ein Set handelt.

Wenn ein Element als Set gekennzeichnet ist, ist es der Einstiegspunkt für das Set mit Elementen, die dieselbe bundleId haben. Sie wird nur auf der Hauptzeitachse eingeblendet – nicht innerhalb des geöffneten Sets.

Auf der Hauptzeitachse werden folgende Elemente angezeigt:
  • Elemente mit isBundleCover, die auf true gesetzt sind
  • Elemente ohne bundleId
In einer Bundle-Unterzeitachse werden folgende Elemente angezeigt:
  • Elemente mit dem betreffenden bundleId UND isBundleCover auf false
Bearbeitbar
location nested object Der geografische Standort, der diesem Element zugeordnet ist. Bearbeitbar
notification nested object Steuert, wie Benachrichtigungen für diesen Artikel auf dem Gerät dargestellt werden. Fehlt diese Angabe, wird keine Benachrichtigung erstellt. Bearbeitbar
notification.deliveryTime datetime Der Zeitpunkt, zu dem die Benachrichtigung gesendet werden soll. Bearbeitbar
notification.level string Beschreibt, wie wichtig die Benachrichtigung ist. Zulässige Werte sind:
  • DEFAULT: Standardbenachrichtigungen. Ein Glockenton wird abgespielt, um die Nutzer zu warnen.
Bearbeitbar
recipients[] list Eine Liste der Nutzer oder Gruppen, für die das Element freigegeben wurde. Bearbeitbar
sourceItemId string Intransparenter String, den Sie verwenden können, um ein Zeitachsenelement Daten in Ihrem eigenen Dienst zuzuordnen. Bearbeitbar
speakableText string Die vorlesbare Version des Inhalts dieses Artikels. Verwenden Sie dieses Feld zusammen mit dem Menüpunkt READ_ALOUD, um Text anzugeben, der beim Vorlesen klarer wird, oder um zusätzliche Informationen zu den Elementen in Glass bereitzustellen.

Glassware sollte auch das Feld „SpeakableType“ angeben. Dieses wird vor diesem Text gesprochen, wenn der zusätzliche Kontext nützlich ist, z. B. wenn der Nutzer nach einer Benachrichtigung anfordert, dass der Artikel vorgelesen wird.
Bearbeitbar
speakableType string Eine gut lesbare Beschreibung des Typs dieses Elements. Dies wird dem Nutzer vor dem Lesen des Inhalts mitgeteilt, wenn der zusätzliche Kontext nützlich ist, z. B. wenn der Nutzer nach einer Benachrichtigung anfordert, dass der Artikel vorgelesen wird.

Das sollte eine kurze, einfache Nominalphrase sein, z. B. „E-Mail“, „SMS“ oder „Daily Planet News“.

Glassware wird empfohlen, dieses Feld für jedes Zeitachsenelement auszufüllen, auch wenn das Element keinen Sprecher oder Text enthält. So kann der Nutzer den Typ des Elements erkennen, ohne auf den Bildschirm zu sehen.
Bearbeitbar
text string Textinhalt dieses Artikels. Bearbeitbar
title string Der Titel dieses Artikels. Bearbeitbar

Antwort

Wenn der Vorgang erfolgreich ist, wird mit dieser Methode eine Zeitachsenressource im Antworttext zurückgegeben.

Beispiele

Hinweis: Bei den für diese Methode verfügbaren Codebeispielen sind nicht alle unterstützten Programmiersprachen vertreten. Eine Liste der unterstützten Sprachen finden Sie auf der Seite für Clientbibliotheken.

Java

Verwendet die Java-Clientbibliothek.

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;

public class MyClass {
  // ...

  /**
   * Update a timeline item in the user's Glass with an optional notification and attachment.
   * 
   * @param service Authorized Mirror service.
   * @param itemId ID of the timeline item to update.
   * @param newText timeline item's text.
   * @param newNotificationLevel Optional notification level, supported values
   *        are {@code null} and "AUDIO_ONLY".
   * @return Updated timeline item on success, {@code null} otherwise.
   */
  public static TimelineItem updateTimelineItem(Mirror service, String itemId, String newText,
      String newNotificationLevel) {
    try {
      // First retrieve the timeline item from the API.
      TimelineItem timelineItem = service.timeline().get(itemId).execute();
      // Update the timeline item's metadata.
      timelineItem.setText(newText);
      if (newNotificationLevel != null && newNotificationLevel.length() > 0) {
        timelineItem.setNotification(new NotificationConfig().setLevel(newNotificationLevel));
      } else {
        timelineItem.setNotification(null);
      }
      return service.timeline().update(itemId, timelineItem).execute();
    } catch (IOException e) {
      System.err.println("An error occurred: " + e);
      return null;
    }
  }

  // ...
}

.NET

Verwendet die .NET-Clientbibliothek.

using System;
using System.IO;

using Google.Apis.Mirror.v1;
using Google.Apis.Mirror.v1.Data;

public class MyClass {
  // ...

  /// <summary>
  /// Update a timeline item in the user's Glass with an optional
  /// notification and attachment.
  /// </summary>
  /// <param name='service'>Authorized Mirror service.</param>
  /// <param name='itemId'>ID of the timeline item to update.</param>
  /// <param name='newText'>Timeline Item's text content.</param>
  /// <param name='newNotificationLevel'>
  /// Optional notification level, supported values are null and
  /// "AUDIO_ONLY".
  /// </param>
  /// <returns>
  /// Updated timeline item on success, null otherwise.
  /// </returns>
  public static TimelineItem UpdateTimelineItem(MirrorService service,
      String itemId, String newText, String newNotificationLevel) {
    try {
      // First retrieve the timeline item from the API.
      TimelineItem timelineItem = service.Timeline.Get(itemId).Fetch();
      // Update the timeline item's metadata.
      timelineItem.Text = newText;
      if (!String.IsNullOrEmpty(newNotificationLevel)) {
        timelineItem.Notification = new NotificationConfig() {
          Level = newNotificationLevel
        };
      } else {
        timelineItem.Notification = null;
      }
      return service.Timeline.Update(timelineItem, itemId).Fetch();
    } catch (Exception e) {
      Console.WriteLine("An error occurred: " + e.Message);
      return null;
    }
  }

  // ...
}

PHP

Verwendet die PHP-Clientbibliothek.

/**
 * Update a timeline item in the user's Glass with an optional
 * notification and attachment.
 *
 * @param Google_MirrorSservice $service Authorized Mirror service.
 * @param string $itemId ID of the timeline item to update.
 * @param string $newText timeline item's text (can be HTML content).
 * @param string $newNotificationLevel Optional notification level,
 *               supported values are {@code null} and "AUDIO_ONLY".
 * @return Google_TimelineItem Updated timeline item on success,
 *         null otherwise.
 */
function updateTimelineItem($service, $itemId, $newText, $newNotificationLevel) {
  try {
    $timelineItem = $service->timeline->get($itemId);
    $timelineItem->setText($newText);
    if ($notificationlevel != null) {
      $notification = new Google_NotificationConfig();
      $notification->setLevel($newNotificationLevel);
      $timelineItem->setNotification($notification);
    } else {
      $timelineItem->setNotification(null);
    }
    return $service->timeline->update($itemId, $timelineItem);
  } catch (Exception $e) {
    print 'An error occurred: ' . $e->getMessage();
    return null;
  }
}

Python

Verwendet die Python-Clientbibliothek.

import io

from apiclient import errors
from apiclient.http import MediaIoBaseUpload
# ...

def update_timeline_item(service, item_id, new_text, 
                         new_notification_level=None):
  """Update a timeline item in the user's Glass.

  Args:
    service: Authorized Mirror service.
    item_id: ID of the timeline item to update.
    new_text: Timeline item's text (can be HTML content).
    new_content_type: Optional attachment's content type (supported content
                      types are 'image/*', 'video/*' and 'audio/*').
    new_attachment: Optional attachment as data string.
    new_notification_level: Optional notification level, supported values are
                            None and 'AUDIO_ONLY'.
  Returns:
    Updated timeline item on success, None otherwise.
  """
  try:
    # First retrieve the timeline item from the API.
    timeline_item = service.timeline().get(id=item_id).execute()
    # Update the timeline item's metadata.
    timeline_item['text'] = new_text
    if new_notification_level:
      timeline_item['notification'] = {'level': new_notification_level}
    elif 'notification' in timeline_item:
      timeline_item.pop('notification')
    return service.timeline().update(id=item_id, body=timeline_item).execute()
  except errors.HttpError, error:
    print 'An error occurred: %s' % error
    return None

Ruby

Verwendet die Ruby-Clientbibliothek.

##
# Update a timeline item in the user's glass.
#
# @param [Google::APIClient] client
#   Authorized client instance.
# @param [String] item_id
#   ID of the timeline item to update.
# @param [String] new_text
#   Timeline item's new text.
# @param [String] new_notification_level
#   Optional new notification level, supported values are nil and 'AUDIO_ONLY'.
# @return [Google::APIClient::Schema::Mirror::V1::TimelineItem]
#   Updated timeline item instance if successful, nil otherwise.
def update_timeline_item(client, item_id, new_text, new_notification_level)
  mirror = client.discovered_api('mirror', 'v1')
  result = client.execute(
    :api_method => mirror.timeline.get,
    :parameters => { 'id' => item_id })
  if result.success?
    timeline_item = result.data
    timeline_item.text = new_text
    if new_notification_level
      timeline_item.notification = { 'level' => new_notification_level }
    else
      timeline_item.notification = nil
    end
    result = client.execute(
      :api_method => mirror.timeline.update,
      :body_object => timeline_item,
      :parameters => { 'id' => item_id })
    if result.success?
      return result.data
    end
  end
  puts "An error occurred: #{result.data['error']['message']}"
end

Einfach loslegen (Go)

Verwendet die Go-Clientbibliothek.

import (
	"code.google.com/p/google-api-go-client/mirror/v1"
	"fmt"
)

// UpdateTimelineItem updates a timeline item in the user's timeline with an
// optional notification and attachment.
func UpdateTimelineItem(g *mirror.Service, itemId string, newNotificationLevel string) (
	*mirror.TimelineItem, error) {
	t, err := g.Timeline.Get(itemId).Do()
	if err != nil {
		fmt.Printf("An error occurred: %v\n", err)
		return nil, err
	}
	t.Text = newText
	if newNotificationLevel != "" {
		t.Notification = &mirror.NotificationConfig{Level: newNotificationLevel}
	} else {
		t.Notification = nil
	}
	r, err := g.Timeline.Update(itemId, t).Do()
	if err != nil {
		fmt.Printf("An error occurred: %v\n", err)
		return nil, err
	}
	return r, nil
}

Rohes HTTP

Verwendet keine Clientbibliothek.

PUT /mirror/v1/timeline/timeline item id HTTP/1.1
Host: www.googleapis.com
Authorization: Bearer auth token
Content-Type: application/json
Content-Length: 26

{ "text": "Hello world" }