Google发布了用于为Google Glass编写应用的Mirror API,并发布了Google Glass设备的最终规格参数。
\Google Glass使用了时间轴的概念,它由一系列包含文本、图片、视频或富HTML的卡片组成。用户可以在镜框上敲击手指,以浏览卡片。卡片由用户通过诸如拍照等方式生成,或是接受自某个用户订阅的服务。卡片可以归类,对此,用户可以选择浏览整个卡片集或是仅仅查看归类后的封面。另外,可以将特定的命令与卡片关联:比如内嵌的Reply或Read Aloud等命令,或是由卡片开发者自定义的命令。
\从开发者的角度看,使用Glass设备意味着就要用 Google Mirror API编写Glass应用。这是一套RESTful API,使用JSON在设备和后端服务之间传输数据,并使用OAuth 2.0进行用户认证。Google则是这些服务与Glass设备之间所有通信的媒介。
\Google提供了Java 和Python实现的入门项目,还提供了许多用于Go、PHP、.NET、Ruby和Dart编程的类库。点击https://glass-java-starter-demo.appspot.com/,可以查看Java入门项目展示。下面是使用HTTP、Java和Python向时间轴中插入卡片的示例:
\\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\" } \
TimelineItemtimelineItem = new TimelineItem();
timelineItem.setText(\"Hello world\");
service.timeline().insert(timelineItem).execute();
timeline_item = {'text': 'Hello world'}
service.timeline().insert(body=timeline_item).execute()
如果成功,服务器应当返回一条201消息,其中带有所创建项目的完整信息:
\\HTTP/1.1 201 Created
Date: Tue, 25 Sep 2012 23:30:11 GMT
Content-Type: application/json
Content-Length: 303
{
\"kind\": \"glass#timelineItem\