अनुमति देना ज़रूरी है
टाइमलाइन में नया आइटम शामिल करता है. उदाहरण देखें.
यह तरीका /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 यूआरआई के लिए, अपलोड के अनुरोध का टाइप.
ये वैल्यू स्वीकार की जाती हैं:
|
अनुमति देना
इस अनुरोध के लिए, इनमें से कम से कम एक दायरे का इस्तेमाल करके अनुमति लेना ज़रूरी है (पुष्टि करने और अनुमति देने के बारे में ज़्यादा पढ़ें).
दायरा |
---|
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 को रेंडर किया जाएगा. ऐसे एचटीएमएल एलिमेंट जिन्हें अनुमति दी गई है - आपके टाइमलाइन कार्ड में इन एलिमेंट का इस्तेमाल किया जा सकता है.
ब्लॉक किए गए एचटीएमएल एलिमेंट: ये एलिमेंट और इनका कॉन्टेंट, एचटीएमएल पेलोड से हटा दिया जाता है.
अन्य एलिमेंट: जो एलिमेंट सूची में नहीं हैं उन्हें हटा दिया जाता है, लेकिन उनका कॉन्टेंट सुरक्षित रखा जाता है. |
लिखा जा सकता है |
isBundleCover |
boolean |
क्या यह आइटम एक बंडल कवर है. अगर किसी आइटम को बंडल के कवर के तौर पर मार्क किया गया है, तो यह आइटम के उस बंडल का एंट्री पॉइंट होगा जिसकी कीमत उस आइटम के bundleId से मेल खाती है. इसे सिर्फ़ मुख्य टाइमलाइन पर दिखाया जाएगा — खुले बंडल में नहीं.मुख्य टाइमलाइन पर, दिखाए गए आइटम ये हैं:
|
लिखा जा सकता है |
location |
nested object |
इस आइटम से जुड़ी भौगोलिक जगह. | लिखा जा सकता है |
menuItems[] |
list |
मेन्यू आइटम की एक सूची, जो उपयोगकर्ता को तब दिखाई जाएगी, जब टाइमलाइन में इस आइटम को चुना जाएगा. | लिखा जा सकता है |
menuItems[].action |
string |
यह नीति, उपयोगकर्ता के मेन्यू का विकल्प चुनने के बाद होने वाले व्यवहार को कंट्रोल करती है. स्वीकृत मान हैं:
|
लिखा जा सकता है |
menuItems[].id |
string |
इस मेन्यू आइटम का आईडी. इसे ऐप्लिकेशन से जनरेट किया जाता है और इसे ओपेक टोकन माना जाता है. | लिखा जा सकता है |
menuItems[].payload |
string |
यह एक सामान्य पेलोड है, जिसका मतलब इस मेन्यू आइटम की कार्रवाई के आधार पर बदलता है.
|
लिखा जा सकता है |
menuItems[].removeWhenSelected |
boolean |
अगर CUSTOM मेन्यू आइटम में 'सही है' पर सेट किया जाता है, तो उस आइटम को चुने जाने के बाद मेन्यू से हटा दिया जाएगा. |
लिखा जा सकता है |
menuItems[].values[] |
list |
CUSTOM आइटम के लिए, हर राज्य में मेन्यू आइटम के दिखाए जाने के तरीके को कंट्रोल करने वाली वैल्यू की सूची. DEFAULT राज्य के लिए वैल्यू देना ज़रूरी है. अगर PENDING या CONFIRMED स्थितियां मौजूद नहीं हैं, तो इन्हें नहीं दिखाया जाएगा. |
लिखा जा सकता है |
menuItems[].values[].displayName |
string |
मेन्यू आइटम के लिए दिखाया जाने वाला नाम. अगर इस प्रॉपर्टी को किसी बिल्ट-इन मेन्यू आइटम के लिए तय किया जाता है, तो उस मेन्यू आइटम के लिए डिफ़ॉल्ट तौर पर इस्तेमाल किया जाने वाला बोला गया निर्देश नहीं दिखाया जाता. | लिखा जा सकता है |
menuItems[].values[].iconUrl |
string |
मेन्यू आइटम के साथ दिखाए जाने वाले आइकॉन का यूआरएल. | लिखा जा सकता है |
menuItems[].values[].state |
string |
वह राज्य जिस पर यह वैल्यू लागू होती है. स्वीकृत मान हैं:
|
लिखा जा सकता है |
notification |
nested object |
यह नीति कंट्रोल करती है कि डिवाइस पर इस आइटम की सूचनाएं किस तरह दिखाई दें. यह जानकारी मौजूद न होने पर, कोई सूचना जनरेट नहीं की जाएगी. | लिखा जा सकता है |
notification.deliveryTime |
datetime |
सूचना भेजे जाने का समय. | लिखा जा सकता है |
notification.level |
string |
यह बताता है कि सूचना कितनी अहम है. स्वीकृत मान हैं:
|
लिखा जा सकता है |
recipients[] |
list |
उन उपयोगकर्ताओं या ग्रुप की सूची जिनके साथ इस आइटम को शेयर किया गया है. | लिखा जा सकता है |
sourceItemId |
string |
ओपेक स्ट्रिंग का इस्तेमाल करके, टाइमलाइन आइटम को अपनी सेवा में मौजूद डेटा से मैप किया जा सकता है. | लिखा जा सकता है |
speakableText |
string |
इस आइटम के कॉन्टेंट का बोलने लायक वर्शन. READ_ALOUD मेन्यू आइटम के साथ, इस फ़ील्ड का इस्तेमाल वह टेक्स्ट देने के लिए करें जो ज़ोर से पढ़कर सुनाए जाने पर साफ़ दिखता हो. इसके अलावा, इसका इस्तेमाल Glass पर दिखाई जा रही चीज़ों के बारे में ज़्यादा जानकारी देने के लिए भी किया जा सकता है.ग्लासवेयर में SpeakingType फ़ील्ड को भी बताया जाना चाहिए. इस फ़ील्ड को इस टेक्स्ट से पहले उन मामलों में बोला जाएगा जहां अतिरिक्त जानकारी काम की हो. उदाहरण के लिए, जब उपयोगकर्ता किसी सूचना के बाद उस आइटम को ज़ोर से पढ़कर सुनाने का अनुरोध करता है. |
लिखा जा सकता है |
speakableType |
string |
इस आइटम के टाइप के बारे में बोलने लायक जानकारी. इसकी सूचना, किसी आइटम का कॉन्टेंट पढ़ने से पहले उपयोगकर्ता को दी जाएगी. ऐसा उन मामलों में होगा जहां ज़्यादा जानकारी काम की हो. उदाहरण के लिए, जब उपयोगकर्ता किसी सूचना के बाद, उस आइटम को ज़ोर से पढ़कर सुनाने का अनुरोध करता है, तो यह सूचना दी जाएगी. यह एक छोटा और आसान वाक्यांश होना चाहिए. जैसे, "ईमेल", "टेक्स्ट मैसेज" या "डेली प्लैनेट न्यूज़ अपडेट". हमारा सुझाव है कि टाइमलाइन पर मौजूद हर आइटम के लिए, कांच से बने इस फ़ील्ड में जानकारी डालें, भले ही आइटम में SpeakingText या टेक्स्ट शामिल न हो. इससे उपयोगकर्ता, स्क्रीन देखे बिना ही यह जान पाएगा कि आइटम किस तरह का है. |
लिखा जा सकता है |
text |
string |
इस आइटम का टेक्स्ट कॉन्टेंट. | लिखा जा सकता है |
title |
string |
इस आइटम का टाइटल. | लिखा जा सकता है |
जवाब
अगर इस तरीके से पुष्टि हो जाती है, तो जवाब के मुख्य हिस्से में यह टाइमलाइन संसाधन दिखाता है.
उदाहरण
ध्यान दें: इस तरीके के लिए दिए गए कोड के उदाहरणों में इसके साथ काम करने वाली सभी प्रोग्रामिंग भाषाएं नहीं दिखाई गई हैं (इसके साथ काम करने वाली भाषाओं की सूची के लिए क्लाइंट लाइब्रेरी वाला पेज देखें).
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 क्लाइंट लाइब्रेरी का इस्तेमाल किया जाता है.
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 क्लाइंट लाइब्रेरी का इस्तेमाल किया जाता है.
/**
* 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 क्लाइंट लाइब्रेरी का इस्तेमाल किया जाता है.
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 क्लाइंट लाइब्रेरी का इस्तेमाल करता हो.
##
# 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--