我试图在谷歌眼镜插入/更新时间轴卡与外部PHP脚本。最终目标是在每次进行更改时从Eclipse插件调用该脚本,并使用来自插件的新数据更新Glass时间轴卡。这可能吗?例如,我如何插入"Hello, World!"卡到谷歌眼镜从PHP脚本运行在我的Apache服务器?我搜索了谷歌和Stack Overflow,但还没有找到任何解释如何做到这一点的东西。我的Glass应用程序使用了Mirror API。
提前感谢您的帮助!
编辑:我想插入一个简单的时间线卡到玻璃使用我的PHP脚本。根据Google开发人员指南,原始HTTP应该是这样的:
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" }
我如何在PHP中编写上述代码以允许我插入一个时间轴卡到玻璃?
另外,如果我的Apache服务器和Glass应用程序在不同的端口上运行,是否有可能使这个POST ?
这是一个PHP函数,它使用Google PHP API客户端库来插入一个简单的时间轴项目。它是从官方时间表中复制的,插入参考文档。
/**
* 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;
}
}
你需要一个初始化的PHP客户端库(或者任何使用镜像API的PHP代码)才能工作。如果您刚刚开始使用PHP和Mirror API,我建议您尝试PHP快速入门项目。