/** * Bootstrap a new user. Do all of the typical actions for a new user: * * <ul> * <li>Creating a timeline subscription * <li>Inserting a contact * <li>Sending the user a welcome message * </ul> */ public static void bootstrapNewUser(HttpServletRequest req, String userId) throws IOException { Credential credential = AuthUtil.newAuthorizationCodeFlow().loadCredential(userId); // Create contact Contact starterProjectContact = new Contact(); starterProjectContact.setId(MainServlet.CONTACT_ID); starterProjectContact.setDisplayName(MainServlet.CONTACT_NAME); starterProjectContact.setImageUrls( Lists.newArrayList(WebUtil.buildUrl(req, "/static/images/chipotle-tube-640x360.jpg"))); starterProjectContact.setAcceptCommands( Lists.newArrayList(new Command().setType("TAKE_A_NOTE"))); Contact insertedContact = MirrorClient.insertContact(credential, starterProjectContact); LOG.info("Bootstrapper inserted contact " + insertedContact.getId() + " for user " + userId); try { // Subscribe to timeline updates Subscription subscription = MirrorClient.insertSubscription( credential, WebUtil.buildUrl(req, "/notify"), userId, "timeline"); LOG.info( "Bootstrapper inserted subscription " + subscription.getId() + " for user " + userId); } catch (GoogleJsonResponseException e) { LOG.warning( "Failed to create timeline subscription. Might be running on " + "localhost. Details:" + e.getDetails().toPrettyString()); } // Send welcome timeline item TimelineItem timelineItem = FeedItem.createSimpleTextTimeLineItem("Welcome to Glass Feed!"); TimelineItem insertedItem = MirrorClient.insertTimelineItem(credential, timelineItem); LOG.info( "Bootstrapper inserted welcome message " + insertedItem.getId() + " for user " + userId); }