Timeline: update

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

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

تتيح هذه الطريقة معرّف الموارد المنتظم /upload، كما تقبل الوسائط المحمّلة بالسمات التالية:

  • الحد الأقصى لحجم الملف: 10 ميغابايت
  • أنواع 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 المحظورة: تتم إزالة هذه العناصر ومحتوياتها من حمولات 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 حقل SpeakableType، الذي سيتم نطقه قبل هذا النص في الحالات التي يكون فيها السياق الإضافي مفيدًا، على سبيل المثال عندما يطلب المستخدم قراءة العنصر بصوت عالٍ بعد تلقي إشعار.
قابلة للكتابة
speakableType string وصف شفهي لنوع هذا العنصر. وسيتم إعلام المستخدم بذلك قبل قراءة محتوى العنصر في الحالات التي يكون فيها السياق الإضافي مفيدًا، مثلاً عندما يطلب المستخدم قراءة العنصر بصوت عالٍ بعد تلقّي إشعار.

يجب أن تكون العبارة قصيرة أو بسيطة، مثل "البريد الإلكتروني" أو "رسالة نصية" أو "آخر الأخبار اليومية على الكوكب".

ننصح باستخدام هذا الحقل لكل عنصر في المخطط الزمني، حتى إذا كان العنصر لا يحتوي على نص يمكن قوله أو حتى لا يتمكن المستخدم من معرفة نوع العنصر بدون النظر إلى الشاشة.
قابلة للكتابة
text string محتوى النص لهذا العنصر. قابلة للكتابة
title string عنوان هذا العنصر. قابلة للكتابة

الإجابة

إذا نجحت هذه الطريقة، فإنها تعرض مورد المخطط الزمني في نص الاستجابة.

أمثلة

ملاحظة: إنّ الأمثلة المرتبطة بالرموز والمتوفرة لهذه الطريقة لا تمثّل كل لغات البرمجة المتوافقة (يُرجى مراجعة صفحة مكتبات البرامج للاطّلاع على قائمة باللغات المتوافقة).

لغة 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" }