谷歌眼镜Mirror API开发指南之Timeline

原文地址:http://bbs.seacat.cn/thread-873-1-2.html



Timeline Items

 

用户通过他们的timeline来获取信息,主要途径是通过timelineitems。也可以称之为卡片。在Glassware中滑动时间轴卡片,可以显示更多的之前或者之后的卡片。

你可以从一个timeline中插入、更新阅读和删除时间轴卡。此外,您可以将对象附加到一个时间表卡上,如位置信息或媒体信息。

 

注意:因为时间轴卡片是用户体验的核心,所以在创建时间表之前先了解下UI guidelines

 

    可操作时间表的完整列表项,referencedocumentation

您可以在menu items(菜单项卡片)上为用户提供选项来执行时间轴卡片。

         

插入一个timeline  item

 

插入一个时间表项目,发布一个JSON表示的时间项REST端点。
注意:用户的谷歌眼镜会删除持续7天的timeline items,如果不更新十天的话,谷歌的服务器也会将其删除。
大多数timelineitem的字段是可选的。最简单的形式,一个时间表项只包含一个简短的短信,就像在下面这个例子.
RawHTTP代码


[mw_shl_code=java,true]POST /mirror/v1/timeline HTTP/1.1
Host: [url=http://www.googleapis.com]www.googleapis.com[/url]
Authorization: Bearer {auth token}
Content-Type: application/json
Content-Length: 26
 
{ "text": "Hello world" }


Java代码:

TimelineItem timelineItem = new TimelineItem();
 
timelineItem.setText("Hello world");
 
service.timeline().insert(timelineItem).execute();


Python代码:

timeline_item = {'text': 'Hello world'}
 
service.timeline().insert(body=timeline_item).execute()


调用成功后,你得到http返回码201和完整副本创建的项目。对于前面的示例,一个成功的响应可能看起来像下面这样:


Raw HTTP:


HTTP/1.1 201 Created
 
Date: Tue, 25 Sep 2012 23:30:11 GMT
 
Content-Type: application/json
 
Content-Length: 303
 
 
 
{
 
 "kind": "glass#timelineItem",
 
 "id": "1234567890",
 
 "selfLink": "https://www.googleapis.com/mirror/v1/timeline/1234567890",
 
 "created": "2012-09-25T23:28:43.192Z",
 
 "updated": "2012-09-25T23:28:43.192Z",
 
 "etag": "\"G5BI0RWvj-0jWdBrdWrPZV7xPKw/t25selcGS3uDEVT6FB09hAG-QQ\"",
 
 "text": "Hello world"
 
}



插入的项将出现在用户的时间表如下


1.png (4.09 KB, 下载次数: 1)

下载附件  保存到相册

2013-12-24 16:51 上传



插入一个带附件的时间表     
     一张图片胜过一千个单词,这是一个更多的比你可以放入一个时间表。为此,您也可以把图片和视频放入一个timeline item。下面是一个示例,如何插入 附件照片在 一个timeline item。

RawHTTP

POST /upload/mirror/v1/timeline HTTP/1.1
 
Host: [url=http://www.googleapis.com]www.googleapis.com[/url]
 
Authorization: Bearer {auth token}
 
Content-Type: multipart/related; boundary="mymultipartboundary"
 
Content-Length: {length}
 
 
 
--mymultipartboundary
 
Content-Type: application/json; charset=UTF-8
 
 
 
{ "text": "A solar eclipse of Saturn. Earth is also in this photo. Can you find it?" }
 
--mymultipartboundary
 
Content-Type: image/jpeg
 
Content-Transfer-Encoding: binary
 
 
 
[binary image data]
 
--mymultipartboundary--



Java代码:


TimelineItem timelineItem = new TimelineItem();
 
timelineItem.setText("Hello world");
 
InputStreamContent mediaContent = new InputStreamContent(contentType, attachment);
 
service.timeline().insert(timelineItem, mediaContent).execute();


Python代码:


timeline_item = {'text': 'Hello world'}
 
media_body = MediaIoBaseUpload(
 
    io.BytesIO(attachment), mimetype=content_type, resumable=True)
 
service.timeline().insert(body=timeline_item, media_body=media_body).execute()


带图像的timelineitem在用户的的谷歌眼镜看起来像下面这样:






注意:在初级水平,附件要通过HTTP Multipart上传。使用Google APIs客户端库media upload可以让这个变得更简单。

连接视频

如果你把视频文件添加到你的timeline item中,我们建议你使用流媒体而不是一次性把整个文件上传上去,Google MirrorAPI支持HTTP live streaming.渐进式下载。以及RTSP协议。RTSP不推荐使用,因为经常会被防火墙阻止。

对于流视频,可以使用PLAY_VIDEO内置菜单来播放指定视频的url地址。可以看到添加内置菜单项和支持的媒体格式的更多信息。

 

注意:附件流视频的url使用内置菜单的PLAY_VIDEOa content-type of video/vnd.google-glass.stream-url已经被弃用了。


随意翻阅

你可以随意的翻阅timeline items,除非只有一张时间轴卡片。也不应该有相同的卡片。分页的items都共享与同一个timeline.id。因此当用户轻触timelineitem时候,应该弹出一个阅读更多菜单项。

谷歌眼镜自动分页显示timeline itemtext。为了让谷歌眼镜自动分页显示html。将article类的属性设置为auto-paginate。就想下面的例子:

 

<article class="auto-paginate">
 
 <h3>Very long list</h3>
 
 <ul>
 
   <li>First item</li>
 
   <li>Second item</li>
 
   <li>Third item</li>
 
   <li>Fourth item</li>
 
   <li>Fifth item</li>
 
   <li>Sixth item</li>
 
   <li>...</li>
 
 </ul>
 
<article>
注意:目前在使用auto-paginate类还不支持部分标记。
为了实现手动分页,在你想显示的每个卡片内容处使用标签。谷歌眼镜显示的每一篇文章内容都标记在一个sub-timeline卡片中,下面的例子就是你创建一个分页的timeline item通过html。
<article>
 
 <section>
 
   <p>First page</p>
 
 </section>
 
</article>
 
 
 
<article>
 
 <section>
 
   <p>Second page</p>
 
 </section>
 
</article>
 
 
 
<article>
 
 <section>
 
   <p>Third page</p>
 
 </section>
 
</article>


默认情况下,分页timeline itmes的第一张卡片设置为封面和用户选择阅读更多菜单项后再次显示,为了防止阅读更多这种情况。你可以在第一个个article使用cover-only


<article class="cover-only">
 
...


同样也支持自动翻页 timeline items


<article class="auto-paginate cover-only">
 
...


绑定

绑定允许你的组里有不同的items,比如个人信息在email的线程中,绑定需要一个界面显示给用户包含哪些其他的sub-timeline卡片.绑定包和正常的时间轴卡片的区别在于卡片右上角有一个卷角。
注意:设置一个具体timeline items的绑定卡,设置他的isBundleCover属性为true.
以下图片显示的绑定了两张卡片的卡,注意页面右上角的卷角。


阅读timeline items

你的服务可以访问所有的timeline items以及所有通过他共享的timeline items。下面介绍如何通过list显示出这些timeline items。

Raw HTTP:

GET /mirror/v1/timeline HTTP/1.1
 
Host: [url=http://www.googleapis.com]www.googleapis.com[/url]
 
Authorization: Bearer {auth token}


Java代码:


TimelineItem timelineItem = new TimelineItem();
 
service.timeline().list().execute();


Python:

service.timeline().list().execute()


你可以使用对timeline items使用其他的操作。比如getupdate  delete

访问附件:

 

你可以访问timeline items通过一个数组属性的 attachments。然后你可以通过attachmentsendpoint获取一个contentUrl来下载文件的二进制数据。

 

注意:附件内容受OAuth 2.0保护,就像其他调用API端点。Google API客户端库提供的二进制内容附件使用媒体下载功能。

 

Raw HTTP

 

GET /mirror/v1/timeline/{itemId}/attachments/{attachmentId} HTTP/1.1
 
Host: [url=http://www.googleapis.com]www.googleapis.com[/url]
 
Authorization: Bearer {auth token}


Java代码


TimelineItem item = service.timeline().get(itemId).execute();
 
String attachmentId = item.getAttachments().get(0).getId();
 
service.attachments().get(itemId, attachmentId).executeAsInputStream();


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值