如果您要執行多項作業,傳送和接收所有 HTTP 訊息所需的時間可能會導致應用程式速度變慢,甚至無法回應。透過批次要求,您可以讓伺服器透過單一 HTTP 要求執行多項作業。基本概念是建立聯絡人動態饋給,並為每個要執行的作業新增項目。
批次要求一次只能包含 100 個作業。如要進一步瞭解批次作業,請參閱「Google 資料通訊協定中的批次處理作業」。變更最多可能需要 24 小時才會在電子郵件地址自動完成功能和聯絡人管理工具中生效。
以下程式碼範例顯示建立 2 個共用聯絡人的批次要求;不過,您也可以使用批次要求查詢、更新及刪除聯絡人。更新和刪除項目需要編輯連結,才能使用樂觀並行處理功能。
<?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>
更改下列內容:
FIRST_NAME
:共用聯絡人的名字,例如 Alex。LAST_NAME
:共用聯絡人的姓氏,例如 Kim。EMAIL_ADDRESS
:共用聯絡人的首選電子郵件地址,例如 alk@gmail.com。