使用 REST 服务同步 SharePoint 项Synchronize SharePoint items using the REST service

若要在 SharePoint 和加载项或服务之间同步项,可以使用 GetListItemChangesSinceToken 资源这样做。If you want to synchronize items between SharePoint and your add-ins or services, you can use the GetListItemChangesSinceToken resource to do so. GetListItemChangesSinceToken 属于 SharePoint REST 服务,对应于 Lists.GetListItemChangesSinceToken Web 服务调用。The GetListItemChangesSinceToken, part of the SharePoint REST service, corresponds to the Lists.GetListItemChangesSinceToken web service call.

执行 POST 请求,请求正文中包含 SP.ChangeLogItemQuery 对象属性对象。Perform a POST request that includes an SP.ChangeLogItemQuery object properties object in the request body.

请求返回 ADO 行集 XML,其中包括与指定查询匹配的任何列表项更改所对应的行。The request returns ADO rowset XML, which includes rows corresponding to any list item change matching the specified query. 若要详细了解这些属性(包括属性数据结构、CAML 元素说明和返回值),请参阅 Lists.GetListItemChangesSinceTokenFor more information about these properties, including property data structures, CAML element descriptions, and return values, see Lists.GetListItemChangesSinceToken.

示例Example

POST https://{site_url}/_api/web/Lists/GetByTitle('Announcements')/GetListItemChangesSinceToken`
Authorization: "Bearer " + accessToken
Content-Type: "application/json"
Content-Length: {length of request body as integer}

{
  "d" : {
  "query": {
    "__metadata": {
      "type": "SP.ChangeLogItemQuery"
    },
    "ViewName": "",
    "Query": "
      <Query>
        <Where>
          <Contains>
            <FieldRef Name='Title' />
            <Value Type='Text'>Te</Value>
          </Contains>
        </Where>'
      </Query>,
    "QueryOptions": "
      <QueryOptions>
        <IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns>
        <DateInUtc>False</DateInUtc>
        <IncludePermissions>TRUE</IncludePermissions>
        <IncludeAttachmentUrls>FALSE</IncludeAttachmentUrls>
        <Folder>Shared Documents/Test1</Folder>
      </QueryOptions>',
    "ChangeToken":"1;3;eee4c6d5-f88a-42c4-8ce1-685122984870;634397182229400000;3710",
    "Contains": "
      <Contains>
        <FieldRef Name="Title"/>
        <Value Type="Text">Testing</Value>
      </Contains>"
    }
  }
}

SP.ChangeLogItemQuery 对象属性SP.ChangeLogItemQuery object properties

属性Property 说明Description
ListNameListName 一个不包括列表的标题,也不包含其 GUID 的字符串。当查询 UserInfo 表时,该字符串包含 UserInfo。使用 GUID 将产生更好的性能。A string that contains either the title or the GUID for the list. When querying the UserInfo table, the string contains UserInfo. Using the GUID results in better performance.
ViewNameViewName 包含视图 GUID 的字符串,可确定要对 queryviewFieldsrowLimit 参数表示的默认视图属性使用的视图。如果未指定此参数,假定使用默认视图。A string that contains the GUID for the view, which determines the view to use for the default view attributes represented by the query, viewFields, and rowLimit parameters. If this argument is not supplied, the default view is assumed.

如果已指定,queryviewFieldsrowLimit 参数的值便会替代视图中的相当设置。If it is supplied, the value of the query, viewFields, or rowLimit parameter overrides the equivalent setting within the view.

例如,如果 viewFields 参数指定的视图的行限制为 100 行,但 rowLimit 参数的值为 1,000 行,响应中返回的是 1,000 行。For example, if the view specified by the viewFields parameter has a row limit of 100 rows, but the rowLimit parameter contains a value of 1000, then 1,000 rows are returned in the response.
QueryQuery Query 元素包含查询,可确定要返回哪些记录以及这些记录的顺序。A Query element containing the query that determines which records are returned and in what order.
QueryOptionsQueryOptions 以下表单中的 XML 段落,其中包含 SPQuery 对象的各个属性的单独节点。An XML fragment in the following form that contains separate nodes for the various properties of the SPQuery object.
ChangeTokenChangeToken 包含请求更改令牌的字符串。A string that contains the change token for the request.

有关此字符串所用格式的说明,请参阅更改日志概述For a description of the format that is used in this string, see Overview of the Change Log. 如果传递的是 NULL 值,列表中的所有项都会返回。If null is passed, all items in the list are returned.
ContainsContains Contains 元素定义了查询的自定义筛选。A Contains element that defines custom filtering for the query.

另请参阅See also