List of usage examples for org.springframework.social.facebook.api.impl FacebookTemplate FacebookTemplate
public FacebookTemplate(String accessToken)
From source file:com.seajas.search.codex.service.social.SocialFacade.java
@Override public Facebook getFacebookTemplate() { Facebook facebook = null;/*from w ww. jav a 2 s . c o m*/ IdentityAccountToken facebookToken = getToken("facebook"); if (facebookToken != null) { facebook = new FacebookTemplate(facebookToken.getAccessToken()); } else { LOG.warn("Could not retrieve valid identity account token for facebook"); } return facebook; }
From source file:gr.abiss.calipso.userDetails.service.impl.UserDetailsServiceImpl.java
/** * @see org.springframework.social.connect.ConnectionSignUp#execute(org.springframework.social.connect.Connection) *//*from w ww . j av a 2 s . c om*/ @Override @Transactional(readOnly = false) public String execute(Connection<?> connection) { //if(LOGGER.isDebugEnabled()){ LOGGER.info("ConnectionSignUp#execute, connection: " + connection); //} //String localUsername = null; String accessToken = connection.createData().getAccessToken(); UserProfile profile = connection.fetchUserProfile(); ConnectionData data = connection.createData(); String socialUsername = profile.getUsername(); if (StringUtils.isBlank(socialUsername)) { LOGGER.info("blank username for profile class: " + profile.getClass()); Object api = connection.getApi(); if (SocialMediaService.FACEBOOK.toString().equalsIgnoreCase(connection.createData().getProviderId())) { Facebook fbApi = new FacebookTemplate(accessToken); User fbProfile = fbApi.userOperations().getUserProfile(); if (fbProfile != null) { socialUsername = fbProfile.getId(); LOGGER.debug("ConnectionSignUp#execute, Got facebook id: " + socialUsername); } } else if (SocialMediaService.LINKEDIN.toString() .equalsIgnoreCase(connection.createData().getProviderId())) { LinkedIn liApi = new LinkedInTemplate(accessToken); LinkedInProfile liProfile = liApi.profileOperations().getUserProfile(); if (liProfile != null) { socialUsername = liProfile.getId(); LOGGER.debug("ConnectionSignUp#execute, Got linkedin id: " + socialUsername); } } } String socialName = profile.getName(); String socialEmail = profile.getEmail(); String socialFirstName = profile.getFirstName(); String socialLastName = profile.getLastName(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("ConnectionSignUp#execute, profile: " + profile + ", data: " + data + ", socialUsername: " + socialUsername + ", socialName: " + socialName + ", socialEmail: " + socialEmail + ", socialFirstName: " + socialFirstName + ", socialLastName: " + socialLastName + ", accessToken: " + accessToken); } // get email from github if empty // if (StringUtils.isNullOrEmpty(socialEmail)) { // Object api = connection.getApi(); // if (SocialMediaService.GITHUB.toString().equalsIgnoreCase(connection.createData().getProviderId())) { // GitHub githubApi = new GitHubTemplate(accessToken);//(GitHub) api; // GitHubUserProfile githubProfile = githubApi.userOperations().getUserProfile(); // LOGGER.debug("ConnectionSignUp#execute, Got github profile: " + githubProfile + ", authorized: " + githubApi.isAuthorized()); // if (githubProfile != null) { // socialEmail = githubProfile.getEmail(); // LOGGER.debug("ConnectionSignUp#execute, Got github email: " + socialEmail); // } // } // } LocalUser user = null; if (!StringUtils.isBlank(socialEmail)) { // LOGGER.debug("ConnectionSignUp#execute, Social email accessible, looking for local user match"); user = localUserService.findByUserNameOrEmail(socialEmail); // if (user != null) { if (LOGGER.isDebugEnabled()) { LOGGER.debug( "ConnectionSignUp#execute, Email matches existing local user, no need to create one"); } //localUsername = user.getUsername(); } else { if (LOGGER.isDebugEnabled()) { LOGGER.debug( "ConnectionSignUp#execute, Email did not match an local user, trying to create one"); } user = new SimpleLocalUser(); user.setActive(true); user.setEmail(socialEmail); user.setUsername(socialEmail); user.setFirstName(socialFirstName); user.setLastName(socialLastName); user.setPassword(UUID.randomUUID().toString()); try { user = localUserService.createForImplicitSignup(user); //localUsername = user.getUsername(); } catch (DuplicateEmailException e) { LOGGER.error("ConnectionSignUp#executeError while implicitly registering user", e); } } } else { if (LOGGER.isDebugEnabled()) { LOGGER.debug( "ConnectionSignUp#execute, Social email was not accessible, unable to implicitly sign in user"); } } //localUserService.createAccount(account); String result = user != null && user.getId() != null ? user.getId().toString() : null; if (LOGGER.isDebugEnabled()) { LOGGER.debug("ConnectionSignUp#execute, returning result: " + result); } return result; }
From source file:com.seajas.search.codex.service.social.SocialProfileServiceTest.java
@Test @Ignore("resolves internet content") public void shouldGetFacebookPage() throws Exception { Facebook f = new FacebookTemplate( "AAAGsPMuLCa0BAAN2TxBMTWDaLFBMY8UJfLqY5R9qycuFcGzTpSD7HBKgaqzfKBxtudxpEeKXXLpypwSBwxD0gZC2gHk6yLXndRGbXJwZDZD"); FqlResultMapper<FacebookProfile> objectFqlResultMapper = new FqlResultMapper<FacebookProfile>() { @Override//w ww . ja v a 2s . com public FacebookProfile mapObject(FqlResult objectValues) { String id = objectValues.getString("page_id"); String username = objectValues.getString("username"); String name = objectValues.getString("name"); String firstName = objectValues.getString("first_name"); String lastName = objectValues.getString("last_name"); String gender = null; System.out.println(objectValues.getString("about")); return new FacebookProfile(id, username, name, firstName, lastName, gender, null); } }; List<FacebookProfile> query = f.fqlOperations().query( "SELECT page_id, name, pic_small, pic_big, pic_square, pic, username, location, about FROM page where page_id in ('144938055520551', '132168606820734')", objectFqlResultMapper); for (FacebookProfile facebookProfile : query) { SocialProfileDto translate = SocialProfileDto.translate(facebookProfile); System.out.println("translate = " + translate); } }