本文整理汇总了Java中com.google.api.services.plus.model.Person类的典型用法代码示例。如果您正苦于以下问题:Java Person类的具体用法?Java Person怎么用?Java Person使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Person类属于com.google.api.services.plus.model包,在下文中一共展示了Person类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAuthenticateTokenParseException
import com.google.api.services.plus.model.Person; //导入依赖的package包/类
@Test(expected = GoogleOauthException.class)
public void testAuthenticateTokenParseException() throws Exception {
GoogleOauthAccessRequestInfo input = prepGoogleCall();
GoogleTokenResponse googleTokenResponse = mock(GoogleTokenResponse.class);
GoogleResponseData googleData = new GoogleResponseData(
googleTokenResponse,
new Person()
);
/* Train the mocks. */
when(
googleOauthService.getUserDataFromGoogle(
anyString(),
anyString(),
anyString(),
anyString()
)
).thenReturn(
googleData
);
when(googleTokenResponse.parseIdToken()).thenThrow(new IOException("test-io-exception"));
/* Make the call. */
toTest.authenticate(input);
}
示例2: testAuthenticate
import com.google.api.services.plus.model.Person; //导入依赖的package包/类
@Test
public void testAuthenticate() throws Exception {
GoogleOauthAccessRequestInfo input = prepGoogleCall();
TokenResponse expected = new TokenResponse(TOKEN);
HmhbUser user = new HmhbUser();
user.setId(USER_ID);
user.setEmail(USER_EMAIL);
user.setAdmin(true);
/* Finish training the mocks. */
when(userService.saveWithGoogleData(eq(USER_EMAIL), any(Person.class))).thenReturn(user);
when(jwtAuthService.generateJwtToken(user)).thenReturn(TOKEN);
/* Make the call. */
TokenResponse actual = toTest.authenticate(input);
/* Verify the results. */
assertEquals(expected, actual);
}
示例3: listPeople
import com.google.api.services.plus.model.Person; //导入依赖的package包/类
/**
* Get list of people user has shared with this app.
*/
private Person listPeople() {
String tokenData = AuthFilter.getToken();
try {
// Build credential from stored token data.
GoogleCredential credential = new GoogleCredential.Builder()
.setJsonFactory(JSON_FACTORY)
.setTransport(TRANSPORT)
.setClientSecrets(CLIENT_ID, CLIENT_SECRET).build()
.setFromTokenResponse(JSON_FACTORY.fromString(
tokenData, GoogleTokenResponse.class));
// Create a new authorized API client.
Plus service = new Plus.Builder(TRANSPORT, JSON_FACTORY, credential)
.setApplicationName(APPLICATION_NAME)
.build();
// Get a list of people that this user has shared with this app.
Person me = service.people().get("me").execute();
// PeopleFeed people = service.people().list("me", "visible").execute();
return me;
} catch (IOException e) {
throw new RestException(e);
}
}
示例4: updateUserInformation
import com.google.api.services.plus.model.Person; //导入依赖的package包/类
/**
* Updates current Tech Gallery user information with user data found on
* Google.
*
* @param user
* Google user
* @param person
* Google Plus person information
* @param tgUser
* Tech Gallery user
*/
private void updateUserInformation(final User user, Person person, TechGalleryUser tgUser) {
String plusEmail = user.getEmail();
String plusPhoto = person.getImage().getUrl();
String plusName = person.getDisplayName();
String currentEmail = tgUser.getEmail();
String currentPhoto = tgUser.getPhoto();
String currentName = tgUser.getName();
if (currentEmail == null || !currentEmail.equals(plusEmail)) {
tgUser.setEmail(plusEmail);
}
if (currentPhoto == null || !currentPhoto.equals(plusPhoto)) {
tgUser.setPhoto(plusPhoto);
}
if (currentName == null || !currentName.equals(plusName)) {
tgUser.setName(plusName);
}
if (tgUser.getGoogleId() == null) {
tgUser.setGoogleId(user.getUserId());
}
}
示例5: getStreamUser
import com.google.api.services.plus.model.Person; //导入依赖的package包/类
@Override
public UserAccount getStreamUser(String uid) {
try {
People peopleSrv = plusSrv.people();
Get getRequest = peopleSrv.get(uid);
Person person = getRequest.execute();
UserAccount streamUser = new GooglePlusAccount(person);
return streamUser;
} catch (IOException e) {
logger.error("Exception for user " + uid);
}
return null;
}
示例6: getOrganizerView
import com.google.api.services.plus.model.Person; //导入依赖的package包/类
public View getOrganizerView(Person item) {
View convertView = mInflater.inflate(R.layout.list_organizer_item, null);
ImageView picture = (ImageView) convertView.findViewById(R.id.icon);
if(item != null) {
if(item.getImage() != null) {
App.getInstance().getPicasso()
.load(item.getImage().getUrl())
.placeholder(R.drawable.ic_no_avatar)
.into(picture);
}
TextView title = (TextView) convertView.findViewById(R.id.title);
title.setText(item.getDisplayName());
}
return convertView;
}
示例7: getStreamUser
import com.google.api.services.plus.model.Person; //导入依赖的package包/类
@Override
public StreamUser getStreamUser(String uid) {
People peopleSrv = plusSrv.people();
try {
Get getRequest = peopleSrv.get(uid);
Person person = getRequest.execute();
StreamUser streamUser = new GooglePlusStreamUser(person);
return streamUser;
} catch (IOException e) {
logger.error("Exception for user " + uid);
}
return null;
}
示例8: saveWithGoogleData
import com.google.api.services.plus.model.Person; //导入依赖的package包/类
@Timed
@Override
public HmhbUser saveWithGoogleData(
@Nonnull String email,
@Nonnull Person profile
) {
LOGGER.debug("saveWithGoogleData called: email={}, profile={}", email, profile);
requireNonNull(email, "email cannot be null");
requireNonNull(profile, "profile cannot be null");
/* This method isn't exposed and is only used by the system, so there isn't a need to check authorization. */
HmhbUser user = dao.findByEmailIgnoreCase(email);
if (user == null) {
user = new HmhbUser();
user.setSuperAdmin(false);
user.setAdmin(false);
user.setEmail(email);
user.setCreatedBy("system-generated");
user.setCreatedOn(auditHelper.getCurrentTime());
} else {
user.setUpdatedBy("system-updated-from-google-login");
user.setUpdatedOn(auditHelper.getCurrentTime());
}
user.setProfileUrl(profile.getUrl());
user.setDisplayName(profile.getDisplayName());
user.setImageUrl(profile.getImage().getUrl());
user.setLastName(profile.getName().getFamilyName());
user.setFirstName(profile.getName().getGivenName());
user.setMiddleName(profile.getName().getMiddleName());
user.setPrefix(profile.getName().getHonorificPrefix());
user.setSuffix(profile.getName().getHonorificSuffix());
LOGGER.debug("updating user info: user={}", user);
return dao.save(user);
}
示例9: GoogleResponseData
import com.google.api.services.plus.model.Person; //导入依赖的package包/类
/**
* Constructs a {@link GoogleResponseData}.
*
* @param googleOauthToken google's oauth token response
* @param googlePlusProfile google's g+ profile response
*/
public GoogleResponseData(
@Nonnull GoogleTokenResponse googleOauthToken,
@Nonnull Person googlePlusProfile
) {
this.googleOauthToken = requireNonNull(googleOauthToken, "googleOauthToken cannot be null");
this.googlePlusProfile = requireNonNull(googlePlusProfile, "googlePlusProfile cannot be null");
}
示例10: testSaveWithGoogleData_NotFound
import com.google.api.services.plus.model.Person; //导入依赖的package包/类
@Test
public void testSaveWithGoogleData_NotFound() throws Exception {
HmhbUser expected = new HmhbUser();
expected.setAdmin(false);
expected.setEmail(EMAIL);
expected.setDisplayName(DISPLAY_NAME);
expected.setFirstName(FIRST_NAME);
expected.setLastName(LAST_NAME);
expected.setImageUrl(IMAGE_URL);
expected.setProfileUrl(PROFILE_URL);
expected.setCreatedBy("system-generated");
expected.setCreatedOn(NOW);
Person.Image image = new Person.Image();
image.setUrl(IMAGE_URL);
Person.Name name = new Person.Name();
name.setFamilyName(LAST_NAME);
name.setGivenName(FIRST_NAME);
Person gPlusProfile = new Person();
gPlusProfile.setUrl(PROFILE_URL);
gPlusProfile.setDisplayName(DISPLAY_NAME);
gPlusProfile.setImage(image);
gPlusProfile.setName(name);
/* Train the mocks. */
when(auditHelper.getCurrentTime()).thenReturn(NOW);
when(dao.findByEmailIgnoreCase(EMAIL)).thenReturn(null);
when(dao.save(expected)).thenReturn(expected);
/* Make the call. */
HmhbUser actual = toTest.saveWithGoogleData(EMAIL, gPlusProfile);
/* Verify the results. */
assertEquals(expected, actual);
}
示例11: getUserInfo
import com.google.api.services.plus.model.Person; //导入依赖的package包/类
private User getUserInfo(GoogleTokenResponse accessToken) {
try {
// Build credential from stored token data.
GoogleCredential credential = new GoogleCredential.Builder()
.setJsonFactory(JSON_FACTORY)
.setTransport(TRANSPORT)
.setClientSecrets(CLIENT_ID, CLIENT_SECRET).build()
.setFromTokenResponse(JSON_FACTORY.fromString(
accessToken.toString(), GoogleTokenResponse.class));
// Create a new authorized API client.
Plus service = new Plus.Builder(TRANSPORT, JSON_FACTORY, credential)
.setApplicationName(APPLICATION_NAME)
.build();
// Get a list of people that this user has shared with this app.
Person me = service.people().get("me").execute();
User newUser = new User();
GoogleIdToken idToken = accessToken.parseIdToken();
newUser.setEmailAddress(idToken.getPayload().getEmail());
newUser.setGoogleId(idToken.getPayload().getSubject());
newUser.setFirstName(me.getName().getGivenName());
newUser.setLastName(me.getName().getFamilyName());
String imageUrl = me.getImage().getUrl();
newUser.setImgUrl(imageUrl);
return newUser;
// PeopleFeed people = service.people().list("me", "visible").execute();
} catch (IOException e) {
throw new RestException(e);
}
}
示例12: handleLogin
import com.google.api.services.plus.model.Person; //导入依赖的package包/类
/**
* This method should be executed whenever a user logs in It check whether the
* user exists on TG's datastore and create them, if not. It also checks if
* the user's email has been changed and update it, in case it was changed.
*
* @param user
* A Google AppEngine API user
* @return A response with the user data as it is on TG datastore
*
* @throws InternalServerErrorException
* in case something goes wrong
* @throws NotFoundException
* in case the information are not founded
* @throws BadRequestException
* in case a request with problem were made.
* @throws OAuthRequestException
* in case of authentication problem
* @throws IOException
* in case of a IO exception
*/
@Override
public TechGalleryUser handleLogin(Integer timezoneOffset, final User user, HttpServletRequest req)
throws NotFoundException, BadRequestException, InternalServerErrorException, IOException,
OAuthRequestException {
authorize(user);
String userEmail = user.getEmail();
String header = req.getHeader("Authorization");
String accesstoken = header.substring(header.indexOf(' ')).trim(); // "Bearer
// ".length
GoogleCredential credential = new GoogleCredential().setAccessToken(accesstoken);
Plus plus = new Plus.Builder(new NetHttpTransport(), new JacksonFactory(), credential)
.setApplicationName(i18n.t("Tech Gallery")).build();
Person person = plus.people().get("me").execute();
TechGalleryUser tgUser = userDao.findByGoogleId(user.getUserId());
// Couldn't find by googleID. Try email
if (tgUser == null) {
tgUser = userDao.findByEmail(userEmail);
}
// Ok, we couldn't find it. Create it.
if (tgUser == null) {
tgUser = new TechGalleryUser();
}
updateUserInformation(user, person, tgUser);
tgUser.setTimezoneOffset(timezoneOffset);
addUser(tgUser);
log.info("User " + tgUser.getName() + " added/updated");
return tgUser;
}
示例13: getUrlFromPersonUrl
import com.google.api.services.plus.model.Person; //导入依赖的package包/类
private String getUrlFromPersonUrl(Person.Urls personUrl) {
if (personUrl.getValue().contains("+")) {
try {
return "+" + URLDecoder.decode(personUrl.getValue().replace("plus.google.com/", "").replace("posts", "").replace("/", "").replace("about", "").replace("u1", "").replace("u0", "").replace("https:", "").replace("http:", "").replace(getArguments().getString("plus_id"), ""), "UTF-8").trim();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return personUrl.getValue();
}
} else {
return personUrl.getValue().replace("plus.google.com/", "").replace("posts", "").replace("/", "").replace("about", "").replace("u1", "").replace("u0", "").replace("https:", "").replace("http:", "").replace(getArguments().getString("plus_id"), "").replaceAll("[^\\d.]", "").substring(0, 21);
}
}
示例14: search
import com.google.api.services.plus.model.Person; //导入依赖的package包/类
/**
* Buscar por usuários.
*
* @param name Nome para usar na busca.
* @param maxResults Máximo de resultados.
* @return Lista de usuários.
*/
public List<Person> search(String name, long maxResults) throws RuntimeException {
try {
Plus.People.Search searchPeople = plus.people().search(name);
searchPeople.setMaxResults(5L);
PeopleFeed peopleFeed;
peopleFeed = searchPeople.execute();
return peopleFeed.getItems();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例15: showPeopleWithName
import com.google.api.services.plus.model.Person; //导入依赖的package包/类
/**
* Buscar e exibir os dados de pessoas que tenham um determinado nome.
*
* @param name Nome.
*/
public void showPeopleWithName(String name) {
List<Person> people = search(name, 5);
for(Person person : people) {
showPerson(person);
System.out.println("\n\n");
}
}