我刚刚开始探索谷歌眼镜的功能。
我想做的是一个简单的玻璃器皿,接收来自用户的视频,当默认的'分享'功能被使用。
我已经看过快速入门项目指南,我成功地在python演示项目中上传了我的视频;我还设法在我的服务器中实现示例PHP项目代码。
然而,我仍然不能弄清楚到底发生了什么,当我点击我的眼镜上的"分享"按钮:哪里发送数据?到我的Glassware,到通用的Mirror API,还是到其他地方?我猜想分享功能正在做一些类似于媒体上传页面中描述的事情,但不清楚是如何做到的。
当我上传图片/视频时,演示项目的代码似乎更新了时间轴事件;但如果我没有错,这段代码只是更新一个已经存在的项目与"我已经收到你的数据!"标题。
(我将在这里报告来自Google的notify.php
示例的相关代码:)
switch ($request['collection']) {
case 'timeline':
// Verify that it's a share
foreach ($request['userActions'] as $i => $user_action) {
if ($user_action['type'] == 'SHARE') {
$timeline_item_id = $request['itemId'];
$timeline_item = $mirror_service->timeline->get($timeline_item_id);
// Patch the item. Notice that since we retrieved the entire item above
// in order to access the caption, we could have just changed the text
// in place and used the update method, but we wanted to illustrate the
// patch method here.
$patch = new Google_TimelineItem();
$patch->setText("PHP Quick Start got your photo! " .
$timeline_item->getText());
$mirror_service->timeline->patch($timeline_item_id, $patch);
break;
}
}
...
实际收到视频的时间和地点?我需要知道这一点,以便在收到数据时执行其他操作。
共享的图片或视频通过快速入门PHP项目mirror-client.php中的download_attachment
函数下载。
函数如下:
/**
* Download an attachment's content.
*
* @param string item_id ID of the timeline item the attachment belongs to.
* @param Google_Attachment $attachment Attachment's metadata.
* @return string The attachment's content if successful, null otherwise.
*/
function download_attachment($item_id, $attachment) {
$request = new Google_HttpRequest($attachment->getContentUrl(), 'GET', null, null);
$httpRequest = Google_Client::$io->authenticatedRequest($request);
if ($httpRequest->getResponseHttpCode() == 200) {
return $httpRequest->getResponseBody();
} else {
// An error occurred.
return null;
}
}