Java源码示例:com.google.api.services.people.v1.PeopleService
示例1
@Override
public ImportResult importItem(UUID jobId,
IdempotentImportExecutor idempotentExecutor,
TokensAndUrlAuthData authData, ContactsModelWrapper data) throws Exception{
JCardReader reader = new JCardReader(data.getVCards());
try {
// TODO(olsona): address any other problems that might arise in conversion
List<VCard> vCardList = reader.readAll();
PeopleService.People peopleService = getOrCreatePeopleService(authData).people();
for (VCard vCard : vCardList) {
Person person = convert(vCard);
idempotentExecutor.executeAndSwallowIOExceptions(
vCard.toString(),
vCard.getFormattedName().toString(),
() -> peopleService.createContact(person).execute().toPrettyString());
}
return ImportResult.OK;
} catch (IOException e) {
return new ImportResult(e);
}
}
示例2
private synchronized PeopleService makePeopleService(TokensAndUrlAuthData authData) {
Credential credential = credentialFactory.createCredential(authData);
return new PeopleService.Builder(
credentialFactory.getHttpTransport(), credentialFactory.getJsonFactory(), credential)
.setApplicationName(GoogleStaticObjects.APP_NAME)
.build();
}
示例3
private synchronized PeopleService makePeopleService(TokensAndUrlAuthData authData) {
Credential credential = credentialFactory.createCredential(authData);
return new PeopleService.Builder(
credentialFactory.getHttpTransport(), credentialFactory.getJsonFactory(), credential)
.setApplicationName(GoogleStaticObjects.APP_NAME)
.build();
}
示例4
@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);
contactsService = new GoogleContactsExporter(peopleService);
when(getBatchGet.setPersonFields(PERSON_FIELDS)).thenReturn(getBatchGet);
when(people.connections()).thenReturn(connections);
when(people.getBatchGet()).thenReturn(getBatchGet);
when(peopleService.people()).thenReturn(people);
}
示例5
@Before
public void setup() throws IOException {
people = mock(People.class);
peopleService = mock(PeopleService.class);
createContact = mock(CreateContact.class);
contactsService = new GoogleContactsImporter(peopleService);
executor = new FakeIdempotentImportExecutor();
when(peopleService.people()).thenReturn(people);
when(people.createContact(any(Person.class))).thenReturn(createContact);
Person person = new Person();
when(createContact.execute()).thenReturn(person);
}
示例6
@Override
protected List<Person> doInBackground(Account... accounts) {
if (mActivityRef.get() == null) {
return null;
}
Context context = mActivityRef.get().getApplicationContext();
try {
GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(
context,
Collections.singleton(CONTACTS_SCOPE));
credential.setSelectedAccount(accounts[0]);
PeopleService service = new PeopleService.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
.setApplicationName("Google Sign In Quickstart")
.build();
ListConnectionsResponse connectionsResponse = service
.people()
.connections()
.list("people/me")
.setFields("names,emailAddresses")
.execute();
return connectionsResponse.getConnections();
} catch (UserRecoverableAuthIOException recoverableException) {
if (mActivityRef.get() != null) {
mActivityRef.get().onRecoverableAuthException(recoverableException);
}
} catch (IOException e) {
Log.w(TAG, "getContacts:exception", e);
}
return null;
}
示例7
@VisibleForTesting
GoogleContactsImporter(PeopleService peopleService) {
this.credentialFactory = null; // unused in tests
this.peopleService = peopleService;
}
示例8
private PeopleService getOrCreatePeopleService(TokensAndUrlAuthData authData) {
return peopleService == null ? makePeopleService(authData) : peopleService;
}
示例9
@VisibleForTesting
GoogleContactsExporter(PeopleService peopleService) {
this.credentialFactory = null; // unused in tests
this.peopleService = peopleService;
}
示例10
private PeopleService getOrCreatePeopleService(TokensAndUrlAuthData authData) {
return peopleService == null ? makePeopleService(authData) : peopleService;
}