// Initial requestList<String>sources=newArrayList<>();sources.add("DIRECTORY_SOURCE_TYPE_DOMAIN_CONTACT");sources.add("DIRECTORY_SOURCE_TYPE_DOMAIN_PROFILE");ListDirectoryPeopleResponsefullSyncResponse=peopleService.people().listDirectoryPeople().setSources(sources).setReadMask("metadata,names,emailAddresses").setRequestSyncToken(true).execute();// Fetch all the pageswhile(fullSyncResponse.getNextPageToken()!=null){fullSyncResponse=peopleService.people().listDirectoryPeople().setSources(sources).setReadMask("metadata,names,emailAddresses").setRequestSyncToken(true).setPageToken(fullSyncResponse.getNextPageToken()).execute();}// Some time passes// Fetch incremental changes using the sync token returned in the last fullSyncResponse.try{ListDirectoryPeopleResponseincrementalSyncResponse=peopleService.people().listDirectoryPeople().setSources(sources).setReadMask("metadata,names,emailAddresses").setSyncToken(fullSyncResponse.getNextSyncToken()).execute();for(Personperson:incrementalSyncResponse.getDirectoryPeople()){handlePerson(person);}// Fetch all the pageswhile(incrementalSyncResponse.getNextPageToken()!=null){incrementalSyncResponse=peopleService.people().listDirectoryPeople.setSources(sources).setReadMask("metadata,names,emailAddresses").setSyncToken(fullSyncResponse.getNextSyncToken()).setPageToken(incrementalSyncResponse.getNextPageToken()).execute();for(Personperson:incrementalSyncResponse.getDirectoryPeople()){handlePerson(person);}}}catch(GoogleJsonResponseExceptione){if(e.getStatusCode()==410){// Sync token expired. Make full sync request.}}voidhandlePerson(Personperson){if(person.getMetadata().getDeleted()){// Handle deleted person}else{// Handle changed person}}
[null,null,["最后更新时间 (UTC):2025-08-29。"],[[["\u003cp\u003eAfter setup, the People API allows you to read directory contacts and profiles within a user's domain.\u003c/p\u003e\n"],["\u003cp\u003eDomain administrators must enable external contact and profile sharing for the API to access domain data.\u003c/p\u003e\n"],["\u003cp\u003eYou can retrieve a list of all directory people, or focus on specific people by using the search functionality with prefix queries.\u003c/p\u003e\n"],["\u003cp\u003eThe API provides methods for efficiently listing directory people that have changed since the last sync, minimizing data transfer.\u003c/p\u003e\n"],["\u003cp\u003eDetailed documentation and code samples in Java and HTTP are available to guide implementation and usage of the API.\u003c/p\u003e\n"]]],["To access directory contacts and profiles, domain admins must enable external sharing. Retrieve lists of directory people using `listDirectoryPeople`, specifying `DIRECTORY_SOURCE_TYPE_DOMAIN_CONTACT` and `DIRECTORY_SOURCE_TYPE_DOMAIN_PROFILE` as sources, and `names,emailAddresses` for read data. To track changes, use the sync token from the initial full sync response. Subsequent requests use this sync token to retrieve incremental changes. Utilize `searchDirectoryPeople` to filter contacts by a prefix query.\n"],null,["# Read Domain Contacts and Profiles\n\n\u003cbr /\u003e\n\nAfter you've completed the steps in [Get Ready to Use the People API](/people/v1/getting-started), you are ready to read directory contacts and profiles.\n\nThe following code samples demonstrate how to send a few simple requests. For a full list of methods, see the [reference documentation](/people/api/rest).\n| **Important:** Reading domain data requires that the domain admin must have [enabled external contact and profile sharing](https://support.google.com/a/answer/6343701) of domain-scoped data for their domain.\n\nList the directory people\n-------------------------\n\nTo\n[get a list of contacts and profiles in the user's domain directory](/people/api/rest/v1/people/listDirectoryPeople),\nuse the following code: \n\n### Protocol\n\n```http\nGET /v1/people:listDirectoryPeople?sources=DIRECTORY_SOURCE_TYPE_DOMAIN_CONTACT&sources=DIRECTORY_SOURCE_TYPE_DOMAIN_PROFILE&readMask=names,emailAddresses HTTP/1.1\nHost: people.googleapis.com\n```\n\n### Java\n\n```java\nList\u003cString\u003e sources = new ArrayList\u003c\u003e();\nsources.add(\"DIRECTORY_SOURCE_TYPE_DOMAIN_CONTACT\");\nsources.add(\"DIRECTORY_SOURCE_TYPE_DOMAIN_PROFILE\");\n\nListDirectoryPeopleResponse response = peopleService.people().listDirectoryPeople()\n .setSources(sources)\n .setReadMask(\"metadata,names,emailAddresses\")\n .execute();\n\nList\u003cPerson\u003e people = response.getPeople();\n```\n\nList the directory people that have changed\n-------------------------------------------\n\n### Java\n\n```java\n// Initial request\nList\u003cString\u003e sources = new ArrayList\u003c\u003e();\nsources.add(\"DIRECTORY_SOURCE_TYPE_DOMAIN_CONTACT\");\nsources.add(\"DIRECTORY_SOURCE_TYPE_DOMAIN_PROFILE\");\n\nListDirectoryPeopleResponse fullSyncResponse = peopleService.people().listDirectoryPeople()\n .setSources(sources)\n .setReadMask(\"metadata,names,emailAddresses\")\n .setRequestSyncToken(true)\n .execute();\n// Fetch all the pages\nwhile (fullSyncResponse.getNextPageToken() != null) {\n fullSyncResponse = peopleService.people().listDirectoryPeople()\n .setSources(sources)\n .setReadMask(\"metadata,names,emailAddresses\")\n .setRequestSyncToken(true)\n .setPageToken(fullSyncResponse.getNextPageToken())\n .execute();\n}\n\n// Some time passes\n\n// Fetch incremental changes using the sync token returned in the last fullSyncResponse.\ntry {\n ListDirectoryPeopleResponse incrementalSyncResponse = peopleService.people().listDirectoryPeople()\n .setSources(sources)\n .setReadMask(\"metadata,names,emailAddresses\")\n .setSyncToken(fullSyncResponse.getNextSyncToken())\n .execute();\n for (Person person : incrementalSyncResponse.getDirectoryPeople()) {\n handlePerson(person);\n }\n \n // Fetch all the pages\n while (incrementalSyncResponse.getNextPageToken() != null) {\n incrementalSyncResponse = peopleService.people().listDirectoryPeople\n .setSources(sources)\n .setReadMask(\"metadata,names,emailAddresses\")\n .setSyncToken(fullSyncResponse.getNextSyncToken())\n .setPageToken(incrementalSyncResponse.getNextPageToken())\n .execute();\n for (Person person : incrementalSyncResponse.getDirectoryPeople()) {\n handlePerson(person);\n }\n }\n} catch (GoogleJsonResponseException e) {\n if (e.getStatusCode() == 410) {\n // Sync token expired. Make full sync request.\n }\n}\n\nvoid handlePerson(Person person) {\n if (person.getMetadata().getDeleted()) {\n // Handle deleted person\n } else {\n // Handle changed person\n }\n}\n```\n| **Note:** Writes may have a propagation delay of several minutes for sync requests. Incremental syncs are not intended for read-after-write use cases.\n\nMore details about sync behavior at [ListDirectory](/people/api/rest/v1/people/listDirectoryPeople).\n\nSearch the directory people\n---------------------------\n\nTo [get a list of contacts and profiles in the user's domain directory matching\na prefix query](/people/api/rest/v1/people/searchDirectoryPeople), use the\nfollowing code: \n\n### Protocol\n\n```http\nPOST /v1/people:searchDirectoryPeople?query=John&sources=DIRECTORY_SOURCE_TYPE_DOMAIN_CONTACT&sources=DIRECTORY_SOURCE_TYPE_DOMAIN_PROFILE&readMask=names,emailAddresses HTTP/1.1\nHost: people.googleapis.com\n```\n\n### Java\n\n```java\nList sources = new ArrayList\u003c\u003e();\nsources.add(\"DIRECTORY_SOURCE_TYPE_DOMAIN_CONTACT\");\nsources.add(\"DIRECTORY_SOURCE_TYPE_DOMAIN_PROFILE\");\n\nSearchDirectoryPeopleResponse response = peopleService.people().searchDirectoryPeople()\n .setQuery(\"John\")\n .setSources(sources)\n .setReadMask(\"metadata,names,emailAddresses\")\n .execute();\n\nList\u003cPerson\u003e people = response.getPeople();\n```"]]