function bootstrap_new_user() { global $base_url; $client = get_google_api_client(); $client->setAccessToken(get_credentials($_SESSION['userid'])); // A glass service for interacting with the Mirror API $mirror_service = new Google_MirrorService($client); $timeline_item = new Google_TimelineItem(); $timeline_item->setText("Welcome to the Mirror API PHP Quick Start"); insert_timeline_item($mirror_service, $timeline_item, null, null); insert_contact($mirror_service, "php-quick-start", "PHP Quick Start", $base_url . "/static/images/chipotle-tube-640x360.jpg"); subscribe_to_notifications($mirror_service, "timeline", $_SESSION['userid'], $base_url . "/notify.php"); }
// 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");
// A glass service for interacting with the Mirror API $mirror_service = new Google_MirrorService($client); 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; } } break; case 'locations': $location_id = $request['itemId']; $location = $mirror_service->locations->get($location_id); // Insert a new timeline card, with a copy of that photo attached $loc_timeline_item = new Google_TimelineItem(); $loc_timeline_item->setText("PHP Quick Start says you are now at " . $location->getLatitude() . " by " . $location->getLongitude()); insert_timeline_item($mirror_service, $loc_timeline_item, null, null); break; default: error_log("I don't know how to process this notification: {$request}"); }
require_once 'mirror-client.php'; require_once 'google-api-php-client/src/Google_Client.php'; require_once 'google-api-php-client/src/contrib/Google_MirrorService.php'; require_once 'util.php'; $client = get_google_api_client(); // Authenticate if we're not already if (!isset($_SESSION['userid']) || get_credentials($_SESSION['userid']) == null) { header('Location: ' . $base_url . '/oauth2callback.php'); exit; } else { verify_credentials(get_credentials($_SESSION['userid'])); $client->setAccessToken(get_credentials($_SESSION['userid'])); } // A glass service for interacting with the Mirror API $mirror_service = new Google_MirrorService($client); $new_timeline_item = new Google_TimelineItem(); switch ($_POST['operation']) { case 'deleteTimelineItem': delete_timeline_item($mirror_service, $_POST['itemId']); $message = "A timeline item has been deleted."; break; } if (isset($_GET['message'])) { $new_timeline_item->setText($_GET['message']); $notification = new Google_NotificationConfig(); $notification->setLevel("DEFAULT"); $new_timeline_item->setNotification($notification); insert_timeline_item($mirror_service, $new_timeline_item, null, null); $message = "Timeline Item inserted!"; } //Load cool stuff to show them.