protected static String getOwnerMail() {
    Authentication currentAuthentication = SecurityContextHolder.getContext().getAuthentication();
    String email = "";
    if (currentAuthentication instanceof SocialAuthenticationToken) {
      SocialAuthenticationToken social = (SocialAuthenticationToken) currentAuthentication;

      switch (social.getProviderId()) {
        case ("google"):
          Google google = (Google) social.getConnection().getApi();
          email = google.plusOperations().getGoogleProfile().getAccountEmail();
          break;
        case ("facebook"):
          Facebook facebook = (Facebook) social.getConnection().getApi();
          email = facebook.userOperations().getUserProfile().getEmail();
          break;
      }
    } else if (currentAuthentication instanceof UsernamePasswordAuthenticationToken) {
      UsernamePasswordAuthenticationToken local =
          (UsernamePasswordAuthenticationToken) currentAuthentication;
      email = (String) local.getPrincipal();
    } else if (currentAuthentication instanceof AnonymousAuthenticationToken) {
      return null;
    }
    return email;
  }
 public void setConnectionValues(Google google, ConnectionValues values) {
   GoogleProfile profile = google.userOperations().getUserProfile();
   values.setProviderUserId(profile.getId());
   values.setDisplayName(profile.getName());
   values.setProfileUrl(profile.getLink());
   values.setImageUrl(profile.getProfilePictureUrl());
 }
 @ResponseBody
 @RequestMapping(value = "/moments/delete", method = POST)
 public void deleteMoment(@RequestBody String id) {
   try {
     google.plusOperations().deleteMoment(id);
   } catch (HttpClientErrorException e) {
     System.out.println(e.getResponseBodyAsString());
   }
 }
 public UserProfile fetchUserProfile(Google google) {
   GoogleProfile profile = google.userOperations().getUserProfile();
   return new UserProfileBuilder()
       .setUsername(profile.getEmail())
       .setEmail(profile.getEmail())
       .setName(profile.getName())
       .setFirstName(profile.getFirstName())
       .setLastName(profile.getLastName())
       .build();
 }
 @ResponseBody
 @RequestMapping(value = "/moments/insert", method = POST)
 public Moment insertMoment(@RequestBody Moment moment) {
   return google.plusOperations().insertMoment(moment);
 }
 @ResponseBody
 @RequestMapping("/moments/list")
 public MomentsPage listMoments(String pageToken) {
   return google.plusOperations().getMoments(pageToken);
 }
 @ResponseBody
 @RequestMapping("/activities/{activityId}/comments")
 public ActivityCommentsPage getComments(
     @PathVariable String activityId, @RequestParam(required = false) String pageToken) {
   return google.plusOperations().getComments(activityId, pageToken);
 }
 @ResponseBody
 @RequestMapping("/activities/{id}")
 public Activity getActivity(@PathVariable String id) {
   return google.plusOperations().getActivity(id);
 }
 @ResponseBody
 @RequestMapping("/activities/list/{profileId}")
 public ActivitiesPage getActivities(@PathVariable String profileId, String pageToken) {
   return google.plusOperations().getActivities(profileId, pageToken);
 }
 @ResponseBody
 @RequestMapping("/activities/search")
 public ActivitiesPage searchPublicActivities(
     String query, @RequestParam(required = false) String pageToken) {
   return google.plusOperations().searchPublicActivities(query, pageToken);
 }
 @ResponseBody
 @RequestMapping("/people/{activityId}/resharers")
 public PeoplePage getResharers(
     @PathVariable String activityId, @RequestParam(required = false) String pageToken) {
   return google.plusOperations().getActivityResharers(activityId, pageToken);
 }
 @ResponseBody
 @RequestMapping("/people/{id}/circles")
 public PeoplePage getCircles(
     @PathVariable String id, @RequestParam(required = false) String pageToken) {
   return google.plusOperations().getPeopleInCircles(id, pageToken);
 }
 @ResponseBody
 @RequestMapping("/people/{id}")
 public Person getPerson(@PathVariable String id) {
   return google.plusOperations().getPerson(id);
 }
 @ResponseBody
 @RequestMapping("/people")
 public PeoplePage searchPeople(String query, @RequestParam(required = false) String pageToken) {
   return google.plusOperations().searchPeople(query, pageToken);
 }