Timeline: insert

इसके लिए, अनुमति देना ज़रूरी है

टाइमलाइन में नया आइटम डालता है. उदाहरण देखें.

यह तरीका /upload यूआरआई के साथ काम करता है और नीचे दी गई विशेषताओं के आधार पर अपलोड किया गया मीडिया स्वीकार करता है:

  • फ़ाइल इससे बड़ी नहीं होनी चाहिए: 10 एमबी
  • स्वीकार किए जाने वाले मीडिया MIME टाइप: image/* , audio/* , video/*

अगर बताया गया हो, तो अपलोड किए गए मीडिया को टाइमलाइन आइटम में अटैचमेंट के तौर पर डाला जाता है.

अनुरोध करें

एचटीटीपी अनुरोध

इस तरीके से, दो अलग-अलग यूआरआई के ज़रिए मीडिया अपलोड करने की सुविधा मिलती है. ज़्यादा जानकारी के लिए, मीडिया अपलोड पर दस्तावेज़ देखें.

  • मीडिया अपलोड अनुरोधों के लिए यूआरआई अपलोड करें:
    POST https://www.googleapis.com/upload/mirror/v1/timeline
  • सिर्फ़ मेटाडेटा के अनुरोधों के लिए मेटाडेटा यूआरआई:
    POST https://www.googleapis.com/mirror/v1/timeline

पैरामीटर

पैरामीटर का नाम वैल्यू ब्यौरा
क्वेरी के ज़रूरी पैरामीटर
uploadType string /upload यूआरआई पर अपलोड का अनुरोध. ये वैल्यू डाली जा सकती हैं:
  • media - आसान अपलोड. किसी भी मेटाडेटा के बिना, सिर्फ़ मीडिया अपलोड करें.
  • multipart - मल्टीपार्ट अपलोड. मीडिया और उसके मेटाडेटा, दोनों को एक ही अनुरोध में अपलोड करें.
  • resumable - फिर से अपलोड किया जा सकता है. कम से कम दो अनुरोधों की सीरीज़ का इस्तेमाल करके, फ़ाइल को फिर से शुरू किया जा सकता है. इसके लिए, पहले अनुरोध में मेटाडेटा शामिल होता है.

अनुमति देना

इस अनुरोध के लिए, इनमें से कम से कम एक दायरे की अनुमति लेना ज़रूरी है. पुष्टि करने और अनुमति देने के बारे में ज़्यादा जानें.

स्कोप
https://www.googleapis.com/auth/glass.timeline
https://www.googleapis.com/auth/glass.location

अनुरोध का मुख्य भाग

अनुरोध के मुख्य हिस्से में, मेटाडेटा के तौर पर इन प्रॉपर्टी के साथ टाइमलाइन संसाधन दें. ज़्यादा जानकारी के लिए, मीडिया अपलोड पर दस्तावेज़ देखें.

प्रॉपर्टी का नाम वैल्यू ब्यौरा ज़रूरी जानकारी
ज़रूरी प्रॉपर्टी नहीं
bundleId string इस आइटम का बंडल आईडी. कई आइटम को एक साथ ग्रुप करने के लिए सेवाएं, एक बंडल आईडी बता सकती हैं. ये आइटम, डिवाइस में किसी टॉप लेवल आइटम के नीचे दिखते हैं. लिखा जा सकता है
canonicalUrl string टाइमलाइन आइटम के ज़रिए दिखाए गए डेटा के कैननिकल/अच्छी क्वालिटी वाले वर्शन पर ले जाने वाला कैननिकल यूआरएल. लिखा जा सकता है
creator nested object वह उपयोगकर्ता या ग्रुप जिसने यह आइटम बनाया है. लिखा जा सकता है
displayTime datetime इस आइटम को टाइमलाइन में देखने का समय, आरएफ़सी 3339 के मुताबिक फ़ॉर्मैट किया जाना चाहिए. इस उपयोगकर्ता की टाइमलाइन, समय के हिसाब से, डिसप्ले समय पर क्रम से लगाई जाती है. इससे यह भी तय होता है कि टाइमलाइन में आइटम कहां दिखाया जाएगा. अगर सेवा ने इसे सेट नहीं किया है, तो डिसप्ले टाइम डिफ़ॉल्ट रूप से updated समय होता है. लिखा जा सकता है
html string इस आइटम का एचटीएमएल कॉन्टेंट. अगर किसी आइटम के लिए text और 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

ब्लॉक किए गए एचटीएमएल एलिमेंट: ये एलिमेंट और उनके कॉन्टेंट, एचटीएमएल पेलोड से हटा दिए जाते हैं.

  • दस्तावेज़ के हेडर: 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 के मेन्यू आइटम के साथ, इस फ़ील्ड का इस्तेमाल, टेक्स्ट को इस तरह से करने के लिए करें कि उसे ज़ोर से पढ़कर सुनाया जा सके. इसके अलावा, उसका इस्तेमाल ग्लास पर दिखने वाले कॉन्टेंट के बारे में ज़्यादा जानकारी देने के लिए भी किया जा सकता है.

Glassware को speakableटाइप फ़ील्ड भी बताना चाहिए, जो इस टेक्स्ट से पहले बोला जाएगा. ऐसा तब किया जाता है, जब ज़्यादा संदर्भ काम का होता है. उदाहरण के लिए, जब उपयोगकर्ता किसी सूचना के बाद आइटम को पढ़ने का अनुरोध करता है.
लिखा जा सकता है
speakableType string इस आइटम के प्रकार का विवरण देने वाला ब्यौरा. जिन मामलों में ज़्यादा जानकारी ज़रूरी हो उन मामलों में, आइटम की सामग्री पढ़ने से पहले उपयोगकर्ता को इसकी सूचना दी जाएगी. उदाहरण के लिए, जब उपयोगकर्ता सूचना पाने के बाद उसे पढ़ने का अनुरोध करता है.

में "ईमेल", "मैसेज" या "रोज़ के ग्रह की खबरों का अपडेट" जैसे छोटे, आसान संज्ञा वाले वाक्यांश होने चाहिए.

Glassware को यह टाइमलाइन आइटम के लिए इस फ़ील्ड को पॉप्युलेट करने के लिए प्रोत्साहित किया जाता है. भले ही, आइटम में speakable टेक्स्ट या टेक्स्ट न हो, ताकि उपयोगकर्ता स्क्रीन को देखे बिना ही आइटम का टाइप जान सके.
लिखा जा सकता है
text string इस आइटम का टेक्स्ट कॉन्टेंट. लिखा जा सकता है
title string इस आइटम का शीर्षक. लिखा जा सकता है

जवाब

अगर यह तरीका काम करता है, तो रिस्पॉन्स के मुख्य भाग में टाइमलाइन का रिसॉर्स दिखता है.

उदाहरण

ध्यान दें: इस तरीके के लिए दिए गए कोड के उदाहरणों में इसके साथ काम करने वाली सभी प्रोग्रामिंग भाषाएं नहीं दिखाई गई हैं (इसके साथ काम करने वाली भाषाओं की सूची के लिए क्लाइंट लाइब्रेरी वाला पेज देखें).

Java

Java क्लाइंट लाइब्रेरी का इस्तेमाल करता है.

import com.google.api.client.http.InputStreamContent;
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;
import java.io.InputStream;

public class MyClass {
  // ...

  /**
   * Insert a new timeline item in the user's glass with an optional
   * notification and attachment.
   * 
   * @param service Authorized Mirror service.
   * @param text timeline item's text.
   * @param contentType Optional attachment's content type (supported content
   *        types are "image/*", "video/*" and "audio/*").
   * @param attachment Optional attachment stream.
   * @param notificationLevel Optional notification level, supported values are
   *        {@code null} and "AUDIO_ONLY".
   * @return Inserted timeline item on success, {@code null} otherwise.
   */
  public static TimelineItem insertTimelineItem(Mirror service, String text, String contentType,
      InputStream attachment, String notificationLevel) {
    TimelineItem timelineItem = new TimelineItem();
    timelineItem.setText(text);
    if (notificationLevel != null && notificationLevel.length() > 0) {
      timelineItem.setNotification(new NotificationConfig().setLevel(notificationLevel));
    }
    try {
      if (contentType != null && contentType.length() > 0 && attachment != null) {
        // Insert both metadata and attachment.
        InputStreamContent mediaContent = new InputStreamContent(contentType, attachment);
        return service.timeline().insert(timelineItem, mediaContent).execute();
      } else {
        // Insert metadata only.
        return service.timeline().insert(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>
  /// Insert a new timeline item in the user's glass with an optional
  /// notification and attachment.
  /// </summary>
  /// <param name='service'>Authorized Mirror service.</param>
  /// <param name='text'>Timeline Item's text.</param>
  /// <param name='contentType'>
  /// Optional attachment's content type (supported content types are
  /// "image/*", "video/*" and "audio/*").
  /// </param>
  /// <param name='attachment'>Optional attachment stream</param>
  /// <param name='notificationLevel'>
  /// Optional notification level, supported values are null and
  /// "AUDIO_ONLY".
  /// </param>
  /// <returns>
  /// Inserted timeline item on success, null otherwise.
  /// </returns>
  public static TimelineItem InsertTimelineItem(MirrorService service,
      String text, String contentType, Stream attachment,
      String notificationLevel) {
    TimelineItem timelineItem = new TimelineItem();
    timelineItem.Text = text;
    if (!String.IsNullOrEmpty(notificationLevel)) {
      timelineItem.Notification = new NotificationConfig() {
        Level = notificationLevel
      };
    }
    try {
      if (!String.IsNullOrEmpty(contentType) && attachment != null) {
        // Insert both metadata and media.
        TimelineResource.InsertMediaUpload request = service.Timeline.Insert(
            timelineItem, attachment, contentType);
        request.Upload();
        return request.ResponseBody;
      } else {
        // Insert metadata only.
        return service.Timeline.Insert(timelineItem).Fetch();
      }
    } catch (Exception e) {
      Console.WriteLine("An error occurred: " + e.Message);
      return null;
    }
  }

  // ...
}

PHP

PHP क्लाइंट लाइब्रेरी का इस्तेमाल करता है.

/**
 * Insert a new timeline item in the user's glass with an optional
 * notification and attachment.
 *
 * @param Google_MirrorService $service Authorized Mirror service.
 * @param string $text timeline item's text.
 * @param string $contentType Optional attachment's content type (supported
 *                            content types are "image/*", "video/*"
 *                            and "audio/*").
 * @param string $attachment Optional attachment content.
 * @param string $notificationLevel Optional notification level,
 *                                  supported values are {@code null}
 *                                  and "AUDIO_ONLY".
 * @return Google_TimelineItem Inserted timeline item on success, otherwise.
 */
function insertTimelineItem($service, $text, $contentType, $attachment,
                            $notificationLevel) {
  try {
    $timelineItem = new Google_TimelineItem();
    $timelineItem->setText($text);
    if ($notificationlevel != null) {
      $notification = new Google_NotificationConfig();
      $notification->setLevel($notificationLevel);
      $timelineItem->setNotification($notification);
    }
    $optParams = array();
    if ($contentType != null && $attachment != null) {
      $optParams['data'] = $attachment;
      $optParams['mimeType'] = $contentType;
    }
    return $service->timeline->insert($timelineItem, $optParams);
  } 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 insert_timeline_item(service, text, content_type=None, attachment=None,
                         notification_level=None):
  """Insert a new timeline item in the user's glass.

  Args:
    service: Authorized Mirror service.
    text: timeline item's text.
    content_type: Optional attachment's content type (supported content types
                  are 'image/*', 'video/*' and 'audio/*').
    attachment: Optional attachment as data string.
    notification_level: Optional notification level, supported values are None
                        and 'AUDIO_ONLY'.

  Returns:
    Inserted timeline item on success, None otherwise.
  """
  timeline_item = {'text': text}
  media_body = None
  if notification_level:
    timeline_item['notification'] = {'level': notification_level}
  if content_type and attachment:
    media_body = MediaIoBaseUpload(
        io.BytesIO(attachment), mimetype=content_type, resumable=True)
  try:
    return service.timeline().insert(
        body=timeline_item, media_body=media_body).execute()
  except errors.HttpError, error:
    print 'An error occurred: %s' % error

Ruby

Ruby क्लाइंट लाइब्रेरी का इस्तेमाल करता है.

##
# Insert a new Timeline Item in the user's glass.
#
# @param [Google::APIClient] client
#   Authorized client instance.
# @param [String] text
#   Timeline item's text.
# @param [String] content_type
#   Optional attachment's content type (supported content types are 'image/*',
#   'video/*' and 'audio/*').
# @param [String] filename
#   Optional attachment's filename.
# @param [String] notification_level
#   Optional notification level, supported values are nil and 'AUDIO_ONLY'.
# @return [Google::APIClient::Schema::Mirror::V1::TimelineItem]
#   Timeline item instance if successful, nil otherwise.
def insert_timeline_item(client, text, content_type, filename,
                         notification_level)
  mirror = client.discovered_api('mirror', 'v1')
  timeline_item = mirror.timeline.insert.request_schema.new({ 'text' => text })
  if notification_level
    timeline_item.notification = { 'level' => notification_level }
  end
  result = nil
  if filename
    media = Google::APIClient::UploadIO.new(filename, content_type)
    result = client.execute(
      :api_method => mirror.timeline.insert,
      :body_object => timeline_item,
      :media => media,
      :parameters => {
        'uploadType' => 'multipart',
        'alt' => 'json'})
  else
    result = client.execute(
      :api_method => mirror.timeline.insert,
      :body_object => timeline_item)
  end
  if result.success?
    return result.data
  else
    puts "An error occurred: #{result.data['error']['message']}"
  end
end

शुरू करें

Go क्लाइंट लाइब्रेरी का इस्तेमाल करता है.

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

// InsertTimelineItem inserts a new timeline item in the user's glass with an
// optional notification and attachment.
func InsertTimelineItem(g *mirror.Service, text string, attachment io.Reader,
	notificationLevel string) (*mirror.TimelineItem, error) {
	t := &mirror.TimelineItem{Text: text}
	if notificationLevel != "" {
		t.Notification = &mirror.NotificationConfig{Level: notificationLevel}
	}
	req := g.Timeline.Insert(t)
	if attachment != nil {
		// Add attachment to the timeline item.
		req.Media(attachment)
	}
	r, err := req.Do()
	if err != nil {
		fmt.Printf("An error occurred: %v\n", err)
		return nil, err
	}
	return r, nil
}

रॉ एचटीटीपी

क्लाइंट लाइब्रेरी का इस्तेमाल नहीं करता.

## A very simple timeline item

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

{ "text": "Hello world" }

## A more complete timeline item with an attachment

POST /mirror/v1/timeline HTTP/1.1
Host: www.googleapis.com
Authorization: Bearer auth token
Content-Type: multipart/related; boundary="mymultipartboundary"
Content-Length: length

--mymultipartboundary
Content-Type: application/json; charset=UTF-8

{
 "text": "Hello world",
 "menuItems": [
   { "action": "REPLY" },
   {
     "action": "CUSTOM",
     "id": "complete"
     "values": [{
       "displayName": "Complete",
       "iconUrl": "http://example.com/icons/complete.png"
     }]
   }
}
--mymultipartboundary
Content-Type: image/jpeg
Content-Transfer-Encoding: binary

binary image data
--mymultipartboundary--