I am trying to insert/update timeline cards in the Google Glass with an external PHP script. The eventual goal is for the script to be called from an Eclipse plugin every time a change is made, and update a Glass timeline card with new data from the plugin. Is this possible? For example, how would I insert a “Hello, World!” card to Google Glass from a PHP script running on my Apache server? I've searched Google and Stack Overflow but have yet to come across anything explaining how to do this. My Glass application uses the Mirror API.
Thank you in advance for your help!
EDIT: I would like to insert a simple timeline card to the Glass using my PHP script. According to the Google developers guide, the raw HTTP should look something like this:
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" }
How can I write the above code in PHP to allow me to insert a timeline card to the Glass?
Also, is it possible to make this POST if my Apache server and Glass app are running on different ports?
Here's a PHP function which uses the Google PHP API Client Library to insert a simple timeline item. It was copied from the official timeline insert reference docs.
/**
* 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;
}
}
You need an initialized PHP client library for this (or any PHP code using the Mirror API) to work. If you're just getting started with PHP and the Mirror API, I recommend you try out the PHP quick start project.