Timeline: update

يتطلّب تفويضًا

لتعديل عنصر للمخطط الزمني. اطّلِع على مثال.

تتوافق هذه الطريقة مع معرّف الموارد المنتظم (URI) /upload وتقبل الوسائط التي تم تحميلها بالخصائص التالية:

  • الحد الأقصى لحجم الملف: 10 ميغابايت
  • أنواع MIME للوسائط المقبولة: audio/* , image/* , video/*

الطلب

طلب HTTP

توفِّر هذه الطريقة وظيفة تحميل الوسائط من خلال عنوانَي URL منفصلَين. للحصول على مزيد من التفاصيل، يمكنك الاطّلاع على المستند حول تحميل الوسائط.

  • تحميل عنوان 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 معرِّف الحزمة لهذه السلعة. يمكن للخدمات تحديد packageId لتجميع العديد من العناصر معًا. وتظهر تحت عنصر واحد من المستوى الأعلى على الجهاز. قابل للكتابة
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 المحظورة: تتم إزالة هذه العناصر ومحتواها من حمولات 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.

يجب أن تحدد Glassware أيضًا حقل speechableType الذي سيتم قوله قبل هذا النص في الحالات التي يكون فيها السياق الإضافي مفيدًا، على سبيل المثال عندما يطلب المستخدم قراءة العنصر بصوت عالٍ بعد الإشعار.
قابل للكتابة
speakableType string تمثّل هذه السمة وصفًا شفهيًا لنوع هذا العنصر. يتم إشعار المستخدم بذلك قبل قراءة محتوى العنصر في الحالات التي يكون فيها السياق الإضافي مفيدًا، على سبيل المثال عندما يطلب المستخدم قراءة العنصر بصوت عالٍ بعد تلقّي إشعار.

يجب أن تكون هذه العبارة اسمية قصيرة وبسيطة مثل "البريد الإلكتروني" أو "رسالة نصية" أو "موجز أخبار Daily Planet".

ننصح باستخدام 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

تستخدم مكتبة برامج Ruby.

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

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