Wykonywanie operacji wsadowych
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Jeśli wykonujesz kilka operacji, czas potrzebny na wysyłanie i odbieranie wszystkich tych komunikatów HTTP może spowodować spowolnienie działania aplikacji i utratę jej responsywności. Za pomocą żądań zbiorczych możesz zlecić serwerowi wykonanie wielu operacji za pomocą pojedynczego żądania HTTP. Zasadniczo chodzi o to, aby utworzyć plik danych z kontaktami i dodać wpis dla każdej operacji, którą chcesz wykonać.
Liczba operacji w ramach żądań zbiorczych jest ograniczona do 100 jednostek. Więcej informacji o operacjach zbiorczych znajdziesz w artykule Przetwarzanie zbiorcze w Google Data Protocol.
Uwzględnienie tych zmian w autouzupełnianiu adresów e-mail i na karcie Kontakt może potrwać do 24 godzin.
Poniższy przykładowy kod pokazuje żądanie zbiorcze, które tworzy 2 wspólne kontakty. Można też użyć żądania zbiorczego, aby wyszukiwać, aktualizować i usuwać kontakty. Aby można było aktualizować i usuwać wpisy, musisz mieć link do edycji, który umożliwia optymistyczną współbieżność.
<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns='http://www.w3.org/2005/Atom'
xmlns:gContact='http://schemas.google.com/contact/2008'
xmlns:gd='http://schemas.google.com/g/2005'
xmlns:batch='http://schemas.google.com/gdata/batch'>
<category scheme='http://schemas.google.com/g/2005#kind'
term='http://schemas.google.com/g/2008#contact' />
<entry>
<batch:id>1</batch:id>
<batch:operation type='insert' />
<category scheme='http://schemas.google.com/g/2005#kind'
term='http://schemas.google.com/g/2008#contact'/>
<gd:name>
<gd:givenName>FIRST_NAME</gd:fullName>
<gd:familyName>LAST_NAME</gd:fullName>
</gd:name>
<gd:email rel='http://schemas.google.com/g/2005#home'
address='EMAIL_ADDRESS' primary='true'/>
</entry>
<entry>
<batch:id>2</batch:id>
<batch:operation type='insert' />
<category scheme='http://schemas.google.com/g/2005#kind'
term='http://schemas.google.com/g/2008#contact'/>
<gd:name>
<gd:givenName>FIRST_NAME</gd:fullName>
<gd:familyName>LAST_NAME</gd:fullName>
</gd:name>
<gd:email rel='http://schemas.google.com/g/2005#home'
address='EMAIL_ADDRESS'
primary='true'/>
</entry>
</feed>
Zastąp następujące elementy:
FIRST_NAME
: imię udostępnionego kontaktu, np. Alex.
LAST_NAME
: nazwisko udostępnionego kontaktu, np. Kim.
EMAIL_ADDRESS
: preferowany adres e-mail udostępnionego kontaktu, np. alk@gmail.com.
O ile nie stwierdzono inaczej, treść tej strony jest objęta licencją Creative Commons – uznanie autorstwa 4.0, a fragmenty kodu są dostępne na licencji Apache 2.0. Szczegółowe informacje na ten temat zawierają zasady dotyczące witryny Google Developers. Java jest zastrzeżonym znakiem towarowym firmy Oracle i jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-03-25 UTC.
[null,null,["Ostatnia aktualizacja: 2025-03-25 UTC."],[],[],null,["# Perform batch operations\n\nIf you're performing several operations, the time it takes to send and receive\nall those HTTP messages can make your app slow and unresponsive. With batch\nrequests, you can have the server perform multiple operations with a single HTTP\nrequest. The basic idea is that you create a contacts feed and add an entry for\neach operation that you want to perform.\n\nBatch requests are limited to 100 operations at a time. You can find more\ninformation about batch operations in\n[Batch Processing in the Google Data Protocol](https://developers.google.com/gdata/docs/batch).\nChanges can take up to 24 hours to be reflected in the email address\nautocomplete and the contact manager.\n\nThe following code sample shows a batch request that creates 2 shared\ncontacts; however, you can also use a batch request to query, update, and delete\ncontacts. The update and delete entries require an edit link for\n[optimistic concurrency](https://developers.google.com/gdata/docs/1.0/reference#Optimistic-concurrency)\nto work. \n\n```xml\n\u003c?xml version='1.0' encoding='UTF-8'?\u003e\n\u003cfeed xmlns='http://www.w3.org/2005/Atom'\n xmlns:gContact='http://schemas.google.com/contact/2008'\n xmlns:gd='http://schemas.google.com/g/2005'\n xmlns:batch='http://schemas.google.com/gdata/batch'\u003e\n \u003ccategory scheme='http://schemas.google.com/g/2005#kind'\n term='http://schemas.google.com/g/2008#contact' /\u003e\n \u003centry\u003e\n \u003cbatch:id\u003e1\u003c/batch:id\u003e\n \u003cbatch:operation type='insert' /\u003e\n \u003ccategory scheme='http://schemas.google.com/g/2005#kind'\n term='http://schemas.google.com/g/2008#contact'/\u003e\n \u003cgd:name\u003e\n \u003cgd:givenName\u003eFIRST_NAME\u003c/gd:fullName\u003e\n \u003cgd:familyName\u003eLAST_NAME\u003c/gd:fullName\u003e\n \u003c/gd:name\u003e\n \u003cgd:email rel='http://schemas.google.com/g/2005#home'\n address='EMAIL_ADDRESS' primary='true'/\u003e\n \u003c/entry\u003e\n \u003centry\u003e\n \u003cbatch:id\u003e2\u003c/batch:id\u003e\n \u003cbatch:operation type='insert' /\u003e\n \u003ccategory scheme='http://schemas.google.com/g/2005#kind'\n term='http://schemas.google.com/g/2008#contact'/\u003e\n \u003cgd:name\u003e\n \u003cgd:givenName\u003eFIRST_NAME\u003c/gd:fullName\u003e\n \u003cgd:familyName\u003eLAST_NAME\u003c/gd:fullName\u003e\n \u003c/gd:name\u003e\n \u003cgd:email rel='http://schemas.google.com/g/2005#home'\n address='EMAIL_ADDRESS'\n primary='true'/\u003e\n \u003c/entry\u003e\n\u003c/feed\u003e\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eFIRST_NAME\u003c/var\u003e: First name of the shared contact---for example, Alex.\n- \u003cvar translate=\"no\"\u003eLAST_NAME\u003c/var\u003e: The last name of the shared contact---for example, Kim.\n- \u003cvar translate=\"no\"\u003eEMAIL_ADDRESS\u003c/var\u003e: The preferred email address of the shared contact---for example, alk@gmail.com."]]