use of com.google.api.services.people.v1.PeopleService.People.Connections in project data-transfer-project by google.
the class GoogleContactsExporter method exportContacts.
private ExportResult<ContactsModelWrapper> exportContacts(TokensAndUrlAuthData authData, Optional<PaginationData> pageData) {
try {
// Set up connection
Connections.List connectionsListRequest = getOrCreatePeopleService(authData).people().connections().list(SELF_RESOURCE);
// Get next page, if we have a page token
if (pageData.isPresent()) {
StringPaginationToken paginationToken = (StringPaginationToken) pageData.get();
connectionsListRequest.setPageToken(paginationToken.getToken());
}
// Get list of connections (nb: not a list containing full info of each Person)
ListConnectionsResponse response = connectionsListRequest.setPersonFields(PERSON_FIELDS).execute();
List<Person> peopleList = response.getConnections();
// Get list of resource names, then get list of Persons
List<String> resourceNames = peopleList.stream().map(Person::getResourceName).collect(Collectors.toList());
GetPeopleResponse batchResponse = getOrCreatePeopleService(authData).people().getBatchGet().setResourceNames(resourceNames).setPersonFields(PERSON_FIELDS).execute();
List<PersonResponse> personResponseList = batchResponse.getResponses();
// Convert Persons to VCards
List<VCard> vCards = personResponseList.stream().map(a -> convert(a.getPerson())).collect(Collectors.toList());
// Determine if there's a next page
StringPaginationToken nextPageData = null;
if (response.getNextPageToken() != null) {
nextPageData = new StringPaginationToken(response.getNextPageToken());
}
ContinuationData continuationData = new ContinuationData(nextPageData);
ContactsModelWrapper wrapper = new ContactsModelWrapper(makeVCardString(vCards));
// Get result type
ResultType resultType = ResultType.CONTINUE;
if (nextPageData == null) {
resultType = ResultType.END;
}
return new ExportResult<ContactsModelWrapper>(resultType, wrapper, continuationData);
} catch (IOException e) {
return new ExportResult<ContactsModelWrapper>(ResultType.ERROR, e.getMessage());
}
}
use of com.google.api.services.people.v1.PeopleService.People.Connections in project data-transfer-project by google.
the class GoogleContactsServiceTest method setup.
@Before
public void setup() throws IOException {
connections = mock(Connections.class);
getBatchGet = mock(GetBatchGet.class);
people = mock(People.class);
peopleService = mock(PeopleService.class);
listConnectionsRequest = mock(Connections.List.class);
createContact = mock(CreateContact.class);
jobDataCache = new InMemoryJobDataCache();
contactsService = new GoogleContactsService(peopleService, jobDataCache);
when(getBatchGet.setPersonFields(PERSON_FIELDS)).thenReturn(getBatchGet);
when(people.connections()).thenReturn(connections);
when(people.getBatchGet()).thenReturn(getBatchGet);
when(people.createContact(any(Person.class))).thenReturn(createContact);
when(peopleService.people()).thenReturn(people);
}
use of com.google.api.services.people.v1.PeopleService.People.Connections in project BachelorPraktikum by lucasbuschlinger.
the class GooglePeople method getAllProfiles.
/**
* Fetches the list of all profiles from the currently logged in user and passes them into the address book controller.
*/
public void getAllProfiles() {
try {
List<Person> persons = peopleService.people().connections().list("people/me").setPersonFields("names,addresses").setPageSize(PAGE_SIZE).execute().getConnections();
for (Person p : persons) {
if (p.getAddresses() != null) {
Contact c = new Contact(p.getNames().get(0).getDisplayName(), p.getAddresses());
AddressBook.getInstance().addContact(c);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
use of com.google.api.services.people.v1.PeopleService.People.Connections in project google-services by googlesamples.
the class RestApiActivity method onConnectionsLoadFinished.
protected void onConnectionsLoadFinished(@Nullable List<Person> connections) {
hideProgressDialog();
if (connections == null) {
Log.d(TAG, "getContacts:connections: null");
mDetailTextView.setText(getString(R.string.connections_fmt, "None"));
return;
}
Log.d(TAG, "getContacts:connections: size=" + connections.size());
// Get names of all connections
StringBuilder msg = new StringBuilder();
for (int i = 0; i < connections.size(); i++) {
Person person = connections.get(i);
if (person.getNames() != null && person.getNames().size() > 0) {
msg.append(person.getNames().get(0).getDisplayName());
if (i < connections.size() - 1) {
msg.append(",");
}
}
}
// Display names
mDetailTextView.setText(getString(R.string.connections_fmt, msg.toString()));
}
use of com.google.api.services.people.v1.PeopleService.People.Connections in project data-transfer-project by google.
the class GoogleContactsService method export.
public ContactsModelWrapper export(ExportInformation continuationInformation) throws IOException {
// Set up connection
Connections.List connectionsList = peopleService.people().connections().list(GoogleContactsConstants.SELF_RESOURCE);
// Get next page, if we have a page token
if (continuationInformation.getPaginationInformation().isPresent()) {
String pageToken = ((StringPaginationToken) continuationInformation.getPaginationInformation().get()).getId();
connectionsList.setPageToken(pageToken);
}
// Get list of connections (nb: not a list containing full info of each Person)
ListConnectionsResponse response = connectionsList.setPersonFields(GoogleContactsConstants.PERSON_FIELDS).execute();
List<Person> peopleList = response.getConnections();
// Get list of resource names, then get list of Persons
List<String> resourceNames = peopleList.stream().map(Person::getResourceName).collect(Collectors.toList());
GetPeopleResponse batchResponse = peopleService.people().getBatchGet().setResourceNames(resourceNames).setPersonFields(GoogleContactsConstants.PERSON_FIELDS).execute();
List<PersonResponse> personResponseList = batchResponse.getResponses();
// Convert Persons to VCards
List<VCard> vCards = personResponseList.stream().map(a -> GoogleContactToVCardConverter.convert(a.getPerson())).collect(Collectors.toList());
// Determine if there's a next page
StringPaginationToken newPage = null;
if (response.getNextPageToken() != null) {
newPage = new StringPaginationToken(response.getNextPageToken());
}
ContinuationInformation newContinuationInformation = null;
if (newPage != null) {
newContinuationInformation = new ContinuationInformation(null, newPage);
}
return new ContactsModelWrapper(vCards, newContinuationInformation);
}
Aggregations