Timeline: update

נדרשת הרשאה

עדכון פריט של ציר הזמן במקום. לעיון בדוגמה

השיטה הזו תומכת ב-URI של /upload ומקבלת קובצי מדיה שהועלו באמצעות המאפיינים הבאים:

  • גודל הקובץ המקסימלי: 10MB
  • סוגים מקובלים של MIME מדיה: audio/* , image/* , video/*

שליחת בקשה

בקשת HTTP

השיטה הזו מספקת פונקציונליות להעלאת מדיה באמצעות שני URI נפרדים. לפרטים נוספים, עיינו במסמך בנושא העלאת מדיה.

  • URI להעלאה, עבור בקשות להעלאת מדיה:
    PUT https://www.googleapis.com/upload/mirror/v1/timeline/id
  • URI של מטא-נתונים, עבור בקשות למטא-נתונים בלבד:
    PUT https://www.googleapis.com/mirror/v1/timeline/id

פרמטרים

שם הפרמטר ערך תיאור
פרמטרים של נתיב
id string המזהה של פריט ציר הזמן.
פרמטרים נדרשים של שאילתה
uploadType string סוג בקשת ההעלאה ל-URI של /upload. ערכים קבילים:
  • mediaהעלאה פשוטה. מעלים את המדיה בלבד, ללא מטא-נתונים.
  • multipartהעלאה בכמה חלקים. העלאת המדיה והמטא-נתונים שלה בבקשה אחת.
  • resumableניתן להמשיך את ההעלאה. יש להעלות את הקובץ באופן שניתן לחידוש ולהשתמש בסדרה של שתי בקשות לפחות, שבהן הבקשה הראשונה כוללת את המטא-נתונים.

הרשאה

לבקשה הזו נדרשת הרשאה עם לפחות אחד מהיקפי ההרשאות הבאים (מידע נוסף על אימות והרשאה).

היקף
https://www.googleapis.com/auth/glass.timeline
https://www.googleapis.com/auth/glass.location

גוף הבקשה

בגוף הבקשה, יש לספק משאב של ציר הזמן עם המאפיינים הבאים בתור המטא-נתונים. מידע נוסף זמין במסמך בנושא העלאת מדיה.

שם הנכס ערך תיאור הערות
מאפיינים אופציונליים
bundleId string מזהה החבילה של הפריט הזה. השירותים יכולים לציין BundleId לקיבוץ פריטים רבים יחד. הן מופיעות מתחת לפריט אחד ברמה העליונה במכשיר. ניתן לכתיבה
canonicalUrl string כתובת URL קנונית שמפנה לגרסה הקנונית/האיכותית של הנתונים שמיוצגים על ידי הפריט בציר הזמן. ניתן לכתיבה
creator nested object המשתמש או הקבוצה שיצרו את הפריט הזה. ניתן לכתיבה
displayTime datetime הזמן שאמור להופיע כאשר הפריט מוצג בציר הזמן, בפורמט בהתאם ל-RFC 3339. ציר הזמן של המשתמש הזה ממוין באופן כרונולוגי בעת הצגתו, כך שגם הוא יקבע היכן הפריט יוצג בציר הזמן. אם השירות לא הוגדר, זמן התצוגה יהיה ברירת המחדל של השעה updated. ניתן לכתיבה
html string תוכן HTML של הפריט הזה. אם מציינים גם את text וגם את html עבור הפריט, html יוצג בציר הזמן.

רכיבי HTML מותרים – אפשר להשתמש ברכיבים האלה בכרטיסי ציר הזמן.

  • כותרות: h1, h2, h3, h4, h5, h6
  • תמונות: img
  • רשימות: li, ol, ul
  • סמנטי HTML5: article, aside, details, figure, figcaption, footer, header, nav, section, summary, time
  • מבני: blockquote, br, div, hr, p, span
  • סגנון: b, big, center, em, i, u, s, small, strike, strong, style, sub, sup
  • טבלאות: table, tbody, td, tfoot, th, thead, tr

רכיבי HTML חסומים: הרכיבים האלה והתוכן שלהם נמחקים ממטענים ייעודיים (payload) של HTML.

  • כותרות המסמכים: head, title
  • הטמעות: audio, embed, object, source, video
  • מסגרות: frame, frameset
  • כתיבת סקריפטים: applet, script

רכיבים אחרים: אלמנטים שאינם רשומים מוסרים, אבל התוכן שלהם נשמר.

ניתן לכתיבה
isBundleCover boolean האם הפריט הזה הוא עטיפת חבילה.

אם פריט מסומן ככיסוי חבילה, הוא ישמש כנקודת הכניסה לחבילת הפריטים שיש להם bundleId זהה לפריט הזה. הוא יוצג רק בציר הזמן הראשי – לא בחבילה הפתוחה.

בציר הזמן הראשי, הפריטים המוצגים הם:
  • פריטים שהמאפיין isBundleCover מוגדר בהם true
  • פריטים שאין להם bundleId
בציר זמן של חבילה, הפריטים המוצגים הם:
  • פריטים שבהם bundleId הנדונים וגם isBundleCover הוגדרו כ-false
ניתן לכתיבה
location nested object המיקום הגיאוגרפי המשויך לפריט זה. ניתן לכתיבה
notification nested object שליטה באופן שבו מוצגות התראות על הפריט הזה במכשיר. אם הפרמטר הזה חסר, לא תיווצר התראה. ניתן לכתיבה
notification.deliveryTime datetime השעה שבה ההודעה אמורה להישלח. ניתן לכתיבה
notification.level string מתאר את מידת החשיבות של ההתראה. הערכים המותרים הם:
  • DEFAULT – התראות על חשיבות ברירת המחדל. יושמע צלצול כדי לשלוח התראה למשתמשים.
ניתן לכתיבה
recipients[] list רשימה של משתמשים או קבוצות שאיתם הפריט שותף. ניתן לכתיבה
sourceItemId string מחרוזת אטומה שבה ניתן להשתמש כדי למפות פריט של ציר זמן לנתונים בשירות שלך. ניתן לכתיבה
speakableText string הגרסה שניתנת להקראה של תוכן הפריט הזה. יחד עם האפשרות בתפריט READ_ALOUD, השתמשו בשדה הזה כדי להוסיף טקסט שיהיה ברור יותר בזמן הקריאה בקול, או כדי לספק מידע מורחב למה שמוצג באופן חזותי ב-Glass.

כלי הזכוכית צריך גם לציין את שדה ה-SpeakableType, שיוקרא לפני הטקסט הזה במקרים שבהם ההקשר הנוסף שימושי, לדוגמה כאשר המשתמש מבקש שפריט יוקרא בקול לאחר התראה.
ניתן לכתיבה
speakableType string תיאור של סוג הפריט, שניתן לבטא אותו. הוא יודיע למשתמש לפני קריאת תוכן הפריט במקרים שבהם ההקשר הנוסף שימושי, למשל כאשר המשתמש מבקש להקריא את הפריט לאחר קבלת הודעה.

עליו להיות ביטוי קצר ופשוט של שם עצם, כגון "אימייל", "הודעת טקסט", או "עדכון יומי של כוכבי לכת".

מומלץ להזין את Glassware עבור השדה הזה עבור כל פריט בציר הזמן, גם אם הפריט לא מכיל SpeakableText או טקסט כדי שהמשתמש יוכל ללמוד את סוג הפריט בלי להסתכל במסך.
ניתן לכתיבה
text string תוכן הטקסט של הפריט הזה. ניתן לכתיבה
title string הכותרת של פריט זה. ניתן לכתיבה

תשובה

אם הצלחת, השיטה הזו מחזירה משאב של ציר זמן בגוף התגובה.

דוגמאות

הערה: דוגמאות הקוד הזמינות לשיטה זו לא מייצגות את כל שפות התכנות הנתמכות (רשימת השפות הנתמכות זמינה בדף של ספריות המשתמשים).

Java

משתמש בספריית הלקוחות של Java.

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

משתמש בספריית הלקוח מסוג .NET

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

משתמש בספריית הלקוח של PHP.

/**
 * 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

משתמש בספריית הלקוחות של Python.

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

משתמש בספריית הלקוחות של Rubby.

##
# 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

Go

נעשה שימוש בספריית הלקוחות של Go.

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 גולמי

לא נעשה שימוש בספריית לקוח.

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