setAccessToken(get_credentials($_SESSION['userid'])); } // A glass service for interacting with the Mirror API $mirror_service = new Google_MirrorService($client); // But first, handle POST data from the form (if there is any) switch ($_POST['operation']) { case 'insertItem': $new_timeline_item = new Google_TimelineItem(); $new_timeline_item->setText($_POST['message']); $notification = new Google_NotificationConfig(); $notification->setLevel("DEFAULT"); $new_timeline_item->setNotification($notification); if (isset($_POST['imageUrl']) && isset($_POST['contentType'])) { insert_timeline_item($mirror_service, $new_timeline_item, $_POST['contentType'], file_get_contents($_POST['imageUrl'])); } else { insert_timeline_item($mirror_service, $new_timeline_item, null, null); } $message = "Timeline Item inserted!"; break; case 'insertItemWithAction': $new_timeline_item = new Google_TimelineItem(); $new_timeline_item->setText("What did you have for lunch?"); $notification = new Google_NotificationConfig(); $notification->setLevel("DEFAULT"); $new_timeline_item->setNotification($notification); $menu_items = array(); // A couple of built in menu items $menu_item = new Google_MenuItem(); $menu_item->setAction("REPLY"); array_push($menu_items, $menu_item); $menu_item = new Google_MenuItem(); $menu_item->setAction("READ_ALOUD"); array_push($menu_items, $menu_item); $new_timeline_item->setSpeakableText("What did you eat? Bacon?"); $menu_item = new Google_MenuItem(); $menu_item->setAction("SHARE"); array_push($menu_items, $menu_item); // A custom menu item $custom_menu_item = new Google_MenuItem(); $custom_menu_value = new Google_MenuValue(); $custom_menu_value->setDisplayName("Drill Into"); $custom_menu_value->setIconUrl($service_base_url . "/static/images/drill.png"); $custom_menu_item->setValues(array($custom_menu_value)); $custom_menu_item->setAction("CUSTOM"); // This is how you identify it on the notification ping $custom_menu_item->setId("safe-for-later"); array_push($menu_items, $custom_menu_item); $new_timeline_item->setMenuItems($menu_items); insert_timeline_item($mirror_service, $new_timeline_item, null, null); $message = "Inserted a timeline item you can reply to"; break; case 'insertTimelineAllUsers': $credentials = list_credentials(); if (count($credentials) > 10) { $message = "Found " . count($credentials) . " users. Aborting to save your quota."; } else { foreach ($credentials as $credential) { $user_specific_client = get_google_api_client(); $user_specific_client->setAccessToken($credential['credentials']); $new_timeline_item = new Google_TimelineItem(); $new_timeline_item->setText("Did you know cats have 167 bones in their tails? Mee-wow!"); $user_specific_mirror_service = new Google_MirrorService($user_specific_client); insert_timeline_item($user_specific_mirror_service, $new_timeline_item, null, null); } $message = "Sent a cat fact to " . count($credentials) . " users."; } break; case 'insertSubscription': $message = subscribe_to_notifications($mirror_service, $_POST['subscriptionId'], $_SESSION['userid'], $base_url . "/notify.php"); break; case 'deleteSubscription': $message = $mirror_service->subscriptions->delete($_POST['subscriptionId']); break; case 'insertContact': insert_contact($mirror_service, $_POST['id'], $_POST['name'], $base_url . "/static/images/chipotle-tube-640x360.jpg"); $message = "Contact inserted. Enable it on MyGlass."; break; case 'deleteContact': delete_contact($mirror_service, $_POST['id']); $message = "Contact deleted."; break; case 'deleteTimelineItem': delete_timeline_item($mirror_service, $_POST['itemId']); $message = "A timeline item has been deleted."; break; } //Load cool stuff to show them. $timeline = $mirror_service->timeline->listTimeline(array('maxResults'=>'3')); try { $contact = $mirror_service->contacts->get("php-quick-start"); } catch (Exception $e) { // no contact found. Meh $contact = null; } $subscriptions = $mirror_service->subscriptions->listSubscriptions(); $timeline_subscription_exists = false; $location_subscription_exists = false; foreach ($subscriptions->getItems() as $subscription) { if ($subscription->getId() == 'timeline') { $timeline_subscription_exists = true; } elseif ($subscription->getId() == 'locations') { $location_subscription_exists = true; } } ?>
ID | getId(); ?> |
---|---|
Text | getText()); ?> |
HTML | getHtml()); ?> |
Attachments | getAttachments() != null) { $attachments = $timeline_item->getAttachments(); foreach ($attachments as $attachment) { ?> |
When you first sign in, this Glassware inserts a welcome message. Use these controls to insert more items into your timeline. Learn more about the timeline APIs here.
By default, this project inserts a single contact that accepts all content types. Learn more about contacts here.
By default a subscription is inserted for changes to the
timeline
collection. Learn more about subscriptions
here.