谷歌眼镜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代码



[plain] view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [mw_shl_code=java,true]POST /mirror/v1/timeline HTTP/1.1  

  2. Host: [url=http://www.googleapis.com]www.googleapis.com[/url]  

  3. Authorization: Bearer {auth token}  

  4. Content-Type: application/json  

  5. Content-Length: 26  

  6. { "text": "Hello world" }  




Java代码:

[java] view plain copy 在CODE上查看代码片 派生到我的代码片
  1. TimelineItem timelineItem = new TimelineItem();  

  2. timelineItem.setText("Hello world");  

  3. service.timeline().insert(timelineItem).execute();  




Python代码:

[python] view plain copy 在CODE上查看代码片 派生到我的代码片
  1. timeline_item = {'text': 'Hello world'}  

  2. service.timeline().insert(body=timeline_item).execute()  




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


Raw HTTP:


[plain] view plain copy 在CODE上查看代码片 派生到我的代码片
  1. HTTP/1.1 201 Created  

  2. Date: Tue, 25 Sep 2012 23:30:11 GMT  

  3. Content-Type: application/json  

  4. Content-Length: 303  

  5. {  

  6. "kind": "glass#timelineItem",  

  7. "id": "1234567890",  

  8. "selfLink": "https://www.googleapis.com/mirror/v1/timeline/1234567890",  

  9. "created": "2012-09-25T23:28:43.192Z",  

  10. "updated": "2012-09-25T23:28:43.192Z",  

  11. "etag": "\"G5BI0RWvj-0jWdBrdWrPZV7xPKw/t25selcGS3uDEVT6FB09hAG-QQ\"",  

  12. "text": "Hello world"  

  13. }  





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


165119rhiqak5o9ghkfq5k.png

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

下载附件保存到相册

2013-12-24 16:51 上传



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

RawHTTP



[plain] view plain copy 在CODE上查看代码片 派生到我的代码片
  1. POST /upload/mirror/v1/timeline HTTP/1.1  

  2. Host: [url=http://www.googleapis.com]www.googleapis.com[/url]  

  3. Authorization: Bearer {auth token}  

  4. Content-Type: multipart/related; boundary="mymultipartboundary"  

  5. Content-Length: {length}  

  6. --mymultipartboundary  

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

  8. { "text": "A solar eclipse of Saturn. Earth is also in this photo. Can you find it?" }  

  9. --mymultipartboundary  

  10. Content-Type: image/jpeg  

  11. Content-Transfer-Encoding: binary  

  12. [binary image data]  

  13. --mymultipartboundary--  





Java代码:


[java] view plain copy 在CODE上查看代码片 派生到我的代码片
  1. TimelineItem timelineItem = new TimelineItem();  

  2. timelineItem.setText("Hello world");  

  3. InputStreamContent mediaContent = new InputStreamContent(contentType, attachment);  

  4. service.timeline().insert(timelineItem, mediaContent).execute();  




Python代码:


[python] view plain copy 在CODE上查看代码片 派生到我的代码片
  1. timeline_item = {'text': 'Hello world'}  

  2. media_body = MediaIoBaseUpload(  

  3.    io.BytesIO(attachment), mimetype=content_type, resumable=True)  

  4. service.timeline().insert(body=timeline_item, media_body=media_body).execute()  




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


165120egw19rupe91z1j95.png





注意:在初级水平,附件要通过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。就想下面的例子:


[html] view plain copy 在CODE上查看代码片 派生到我的代码片
  1. <articleclass="auto-paginate">

  2. <h3>Very long list</h3>

  3. <ul>

  4. <li>First item</li>

  5. <li>Second item</li>

  6. <li>Third item</li>

  7. <li>Fourth item</li>

  8. <li>Fifth item</li>

  9. <li>Sixth item</li>

  10. <li>...</li>

  11. </ul>

  12. <article>

  13. 注意:目前在使用auto-paginate类还不支持部分标记。  

  14. 为了实现手动分页,在你想显示的每个卡片内容处使用标签。谷歌眼镜显示的每一篇文章内容都标记在一个sub-timeline卡片中,下面的例子就是你创建一个分页的timeline item通过html。  

  15. <article>

  16. <section>

  17. <p>First page</p>

  18. </section>

  19. </article>

  20. <article>

  21. <section>

  22. <p>Second page</p>

  23. </section>

  24. </article>

  25. <article>

  26. <section>

  27. <p>Third page</p>

  28. </section>

  29. </article>



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


[html] view plain copy 在CODE上查看代码片 派生到我的代码片
  1. <articleclass="cover-only">

  2. ...  




同样也支持自动翻页 timeline items


[html] view plain copy 在CODE上查看代码片 派生到我的代码片
  1. <articleclass="auto-paginate cover-only">

  2. ...  




绑定

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

以下图片显示的绑定了两张卡片的卡,注意页面右上角的卷角。

165120u69zxv5nngpi6xpa.jpg
165120zv8yz5rbcvjf1jfr.jpg
165121pz0nu7vg3n098evk.jpg


阅读timeline items

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

Raw HTTP:



[plain] view plain copy 在CODE上查看代码片 派生到我的代码片
  1. GET /mirror/v1/timeline HTTP/1.1  

  2. Host: [url=http://www.googleapis.com]www.googleapis.com[/url]  

  3. Authorization: Bearer {auth token}  




Java代码:


[java] view plain copy 在CODE上查看代码片 派生到我的代码片
  1. TimelineItem timelineItem = new TimelineItem();  

  2. service.timeline().list().execute();  




Python:

[python] view plain copy 在CODE上查看代码片 派生到我的代码片
  1. service.timeline().list().execute()  




你可以使用对timeline items使用其他的操作。比如get, updatedelete

访问附件:

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

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

Raw HTTP


[plain] view plain copy 在CODE上查看代码片 派生到我的代码片
  1. GET /mirror/v1/timeline/{itemId}/attachments/{attachmentId} HTTP/1.1  

  2. Host: [url=http://www.googleapis.com]www.googleapis.com[/url]  

  3. Authorization: Bearer {auth token}  



Java代码


[java] view plain copy 在CODE上查看代码片 派生到我的代码片
  1. TimelineItem item = service.timeline().get(itemId).execute();  

  2. String attachmentId = item.getAttachments().get(0).getId();  

  3. service.attachments().get(itemId, attachmentId).executeAsInputStream();  



你可能感兴趣的:(开发,服务器,谷歌,时间表,Guidelines)