Timeline: update

Autorisierung erforderlich

Aktualisiert ein Zeitachsenelement. Beispiel ansehen

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

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

Anfrage

HTTP-Anfrage

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

  • Upload-URI für Anfragen zum Hochladen von Medien:
    PUT https://www.googleapis.com/upload/mirror/v1/timeline/id
  • Metadaten-URI für reine Metadatenanfragen:
    PUT https://www.googleapis.com/mirror/v1/timeline/id

Parameter

Parametername Wert Beschreibung
Pfadparameter
id string Die ID des Zeitachsenelements.
Erforderliche Abfrageparameter
uploadType string Die Art der Uploadanfrage an den /upload-URI. Zulässige Werte sind: <ph type="x-smartling-placeholder">
    </ph>
  • media: Einfacher Upload. Laden Sie nur die Medien ohne Metadaten hoch.
  • multipartMehrteiliger Upload. Laden Sie sowohl die Medien als auch die zugehörigen Metadaten in einer Anfrage hoch.
  • resumableFortsetzbarer Upload. Laden Sie die Datei fortsetzbar mit einer Reihe von mindestens zwei Anfragen hoch, 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).

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

Anfragetext

Geben Sie im Anfragetext eine Zeitachsenressource mit den folgenden Eigenschaften als Metadaten an. Weitere Informationen finden Sie im Dokument zum Medien-Upload.

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

Zulässige HTML-Elemente: Sie können diese Elemente in Ihren Zeitachsenkarten verwenden.

  • Ü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 ihr Inhalt werden aus HTML-Nutzlasten entfernt.

  • Dokumentüberschriften: head, title
  • Einbettungen: audio, embed, object, source, video
  • Rahmen: frame, frameset
  • Scripting: applet, script

Andere Elemente: Nicht aufgeführte Elemente werden entfernt, ihr Inhalt bleibt jedoch erhalten.

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

Wenn ein Artikel als Set-Cover markiert ist, ist er der Einstiegspunkt für das Set mit Artikeln, die dieselbe bundleId haben wie dieser Artikel. Sie wird nur auf der Hauptzeitachse angezeigt, nicht im geöffneten Set.

Auf der Hauptzeitachse werden folgende Elemente angezeigt:
  • Elemente, für die „isBundleCover“ auf „true“ festgelegt ist
  • Artikel ohne bundleId
In einer Paket-Unterzeitachse werden folgende Elemente angezeigt:
  • Artikel, bei denen der betreffende bundleId UND isBundleCover auf false festgelegt ist
Bearbeitbar
location nested object Der mit diesem Element verknüpfte geografische Standort. Bearbeitbar
notification nested object Steuert, wie Benachrichtigungen für dieses Element auf dem Gerät angezeigt werden. Fehlt diese Angabe, wird keine Benachrichtigung generiert. Bearbeitbar
notification.deliveryTime datetime Der Zeitpunkt, zu dem die Benachrichtigung zugestellt werden soll. Bearbeitbar
notification.level string Beschreibt, wie wichtig die Benachrichtigung ist. Zulässige Werte:
  • DEFAULT: Benachrichtigungen von standardmäßiger Wichtigkeit. Nutzer werden durch einen Glockenton gewarnt.
Bearbeitbar
recipients[] list Eine Liste der Nutzer oder Gruppen, für die dieses Element freigegeben wurde. Bearbeitbar
sourceItemId string Undurchsichtiger String, mit dem Sie ein Zeitachsenelement Daten in Ihrem eigenen Dienst zuordnen können. Bearbeitbar
speakableText string Die vorlesbare Version des Inhalts dieses Elements. Verwenden Sie dieses Feld zusammen mit dem Menüpunkt READ_ALOUD für Text, der beim Vorlesen klarer ist, oder um ausführlichere Informationen zu dem zu geben, was auf Glass angezeigt wird.

Glassware sollte außerdem das Feld „SpeakableType“ angeben, das vor diesem Text vorgelesen wird, wenn der zusätzliche Kontext nützlich ist, z. B. wenn der Nutzer das Vorlesen des Elements nach einer Benachrichtigung anfordert.
Bearbeitbar
speakableType string Eine vorlesbare Beschreibung des Elementtyps. Dies wird dem Nutzer vor dem Lesen des Inhalts angezeigt, wenn der zusätzliche Kontext nützlich ist, z. B. wenn der Nutzer anfordert, dass der Artikel nach einer Benachrichtigung vorgelesen wird.

Dies sollte eine kurze, einfache Wortgruppe wie „Email“, „SMS“ oder „Daily Planet News Update“ sein.

Glassware wird empfohlen, dieses Feld für jedes Zeitachsenelement auszufüllen, auch wenn das Element keinen speechableText oder Text enthält. So können Nutzer den Typ des Elements kennenlernen, ohne auf den Bildschirm sehen zu müssen.
Bearbeitbar
text string Textinhalt dieses Elements. Bearbeitbar
title string Der Titel dieses Elements. 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

Ok

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
}

HTTP-Rohdaten

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