使用外部PHP脚本插入玻璃时间线卡
我正在尝试使用外部PHP脚本在Google Glass中插入/更新时间线卡。最终的目标是在每次进行更改时从Eclipse插件调用脚本,并使用插件中的新数据更新Glass timeline卡。这可能吗?例如,如何从Apache服务器上运行的PHP脚本向Google Glass插入“Hello,World!”卡?我搜索过Google和Stack Overflow,但还没有找到任何解释如何做到这一点的方法。我的Glass应用程序使用镜像API 提前感谢您的帮助 编辑: 我想用我的PHP脚本在玻璃上插入一张简单的时间线卡。根据谷歌开发者指南,原始HTTP应该是这样的:使用外部PHP脚本插入玻璃时间线卡,php,apache,google-glass,google-mirror-api,Php,Apache,Google Glass,Google Mirror Api,我正在尝试使用外部PHP脚本在Google Glass中插入/更新时间线卡。最终的目标是在每次进行更改时从Eclipse插件调用脚本,并使用插件中的新数据更新Glass timeline卡。这可能吗?例如,如何从Apache服务器上运行的PHP脚本向Google Glass插入“Hello,World!”卡?我搜索过Google和Stack Overflow,但还没有找到任何解释如何做到这一点的方法。我的Glass应用程序使用镜像API 提前感谢您的帮助 编辑: 我想用我的PHP脚本在玻璃上插入
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应用程序运行在不同的端口上,是否可以发表这篇文章?这里有一个PHP函数,它使用Google PHP API客户端库插入一个简单的时间线项。这是从官员那里抄来的
您需要一个初始化的PHP客户机库才能使其(或任何使用镜像API的PHP代码)正常工作。如果您刚刚开始使用PHP和Mirror API,我建议您尝试。您的问题并不清楚您的问题出在哪里。您在让Eclipse插件向PHP服务器发送消息或PHP服务器向Glass添加卡时遇到问题吗。你能更新你的问题(然后评论说你已经更新了)来提供更多的细节吗?我道歉。我已经删除了“Eclipse插件”标签并编辑了我的问题。如果还不清楚,请告诉我。谢谢你的回复。如果我的PHP脚本和Glassware应用程序运行在不同的端口上,是否可以执行此操作?在本例中,PHP脚本是您的Glassware应用程序。由于它使用镜像API,Google处理所有数据的洗牌,因此您根本不需要打开任何套接字。
/**
* 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;
}
}