API Sites cổ điển cho phép các ứng dụng của bạn truy cập, xuất bản và sửa đổi nội dung trong một trang web được tạo bằng Google Sites. Ngoài ra, ứng dụng của bạn có thể yêu cầu danh sách hoạt động gần đây, tìm nạp revisionhistory và tải lên/tải xuống tệp đính kèm và tệp.
Đối tượng
Tài liệu này giả định rằng bạn hiểu những ý tưởng chung đằng sau giao thức API dữ liệu của Google.
Tài liệu này dành cho những lập trình viên muốn viết các ứng dụng có thể tương tác với Google Sites. Tài liệu này cung cấp một loạt ví dụ về các hoạt động tương tác cơ bản của Data API bằng cách sử dụng XML/HTTP thô, kèm theo phần giải thích. Sau khi đọc tài liệu này, bạn có thể tìm hiểu thêm về cách tương tác với API bằng thư viện ứng dụng của chúng tôi bằng cách đọc các ví dụ theo ngôn ngữ cụ thể trong các hướng dẫn khác trên thanh điều hướng bên trái.
Để tham khảo tài liệu trong hướng dẫn này, hãy xem hướng dẫn tham khảo.
Ủy quyền yêu cầu
Khi yêu cầu dữ liệu người dùng không công khai, ứng dụng của bạn phải có mã uỷ quyền. Mã này cũng giúp Google xác định ứng dụng của bạn.
Giới thiệu về giao thức cấp phép
Ứng dụng của bạn phải sử dụng OAuth 2.0 để cấp phép các yêu cầu. Chúng tôi không hỗ trợ giao thức cấp phép nào khác. Nếu ứng dụng của bạn sử dụng chức năng Đăng nhập bằng Google, thì Google sẽ giúp bạn xử lý một số bước trong quá trình cấp phép.
Cấp phép cho các yêu cầu bằng OAuth 2.0
Các yêu cầu đối với Google Sites Data API về dữ liệu người dùng không công khai phải được một người dùng đã xác thực uỷ quyền.
Các chi tiết của quy trình cấp phép đối với OAuth 2.0 sẽ khác nhau đôi chút tuỳ thuộc vào loại ứng dụng bạn đang viết. Quy trình chung sau đây áp dụng cho tất cả các loại ứng dụng:
- Khi tạo ứng dụng của mình, bạn sẽ đăng ký ứng dụng bằng Google API Console. Sau đó, Google cung cấp thông tin bạn sẽ cần sau này, chẳng hạn như mã ứng dụng khách và mật khẩu ứng dụng khách.
- Kích hoạt Google Sites Data API trong Google API Console. (Nếu API không được liệt kê trong API Console, thì hãy bỏ qua bước này.)
- Khi cần quyền truy cập vào dữ liệu người dùng, ứng dụng sẽ yêu cầu Google cung cấp phạm vi truy cập cụ thể.
- Google hiển thị màn hình yêu cầu sự đồng ý cho người dùng để hỏi xem họ có cho phép ứng dụng của bạn yêu cầu một số dữ liệu của họ hay không.
- Nếu người dùng đồng ý, thì Google sẽ cấp cho ứng dụng của bạn một mã truy cập ngắn hạn.
- Sau đó, ứng dụng yêu cầu dữ liệu người dùng và đính kèm mã truy cập trong yêu cầu.
- Nếu xác định rằng yêu cầu của bạn và mã này là hợp lệ, Google sẽ trả về dữ liệu mà ứng dụng yêu cầu.
Một số quy trình cấp phép có các bước bổ sung khác, chẳng hạn như sử dụng mã làm mới để lấy mã truy cập mới. Để biết thông tin chi tiết về quy trình cho các loại ứng dụng khác nhau, hãy xem tài liệu về OAuth 2.0 của Google.
Dưới đây là thông tin về phạm vi truy cập OAuth 2.0 đối với Google Sites Data API:
https://sites.google.com/feeds/
Để yêu cầu quyền truy cập bằng OAuth 2.0, ứng dụng của bạn cần thông tin về mức truy cập, cũng như thông tin mà Google cung cấp khi bạn đăng ký ứng dụng của mình (chẳng hạn như mã ứng dụng khách và mật khẩu ứng dụng khách).
Chỉ định một phiên bản
Mọi yêu cầu mà bạn gửi đến Google Sites Data API đều phải chỉ định phiên bản 1.4. Để chỉ định số phiên bản, hãy dùng tiêu đề HTTP GData-Version:
GData-Version: 1.4
Ngoài ra, nếu không thể đặt tiêu đề HTTP, bạn có thể chỉ định v=1.4 làm tham số truy vấn trong URL. Tuy nhiên, bạn nên dùng tiêu đề HTTP nếu có thể.
Lưu ý: Các thư viện ứng dụng sẽ tự động cung cấp tiêu đề phiên bản thích hợp, vì vậy, đừng sử dụng tham số truy vấn v=1.4 khi bạn đang dùng một thư viện ứng dụng.
Nguồn cấp dữ liệu trang web
Bạn có thể dùng nguồn cấp dữ liệu trang web để liệt kê những trang web trên Google Sites mà người dùng sở hữu hoặc có quyền xem, đồng thời sửa đổi tiêu đề của một trang web hiện có. Đối với miền G Suite, bạn cũng có thể dùng tính năng này để tạo hoặc sao chép toàn bộ trang web.
Trang web đăng thông tin
Để liệt kê những trang web mà người dùng có quyền truy cập, hãy gửi một yêu cầu GET đã xác thực đến URL sau:
https://sites.google.com/feeds/site/domainName| Tham số nguồn cấp dữ liệu | Mô tả |
|---|---|
domainName | "site" hoặc miền của tên miền được lưu trữ trên G Suite (ví dụ: example.com). |
Phản hồi sẽ chứa một nguồn cấp dữ liệu có danh sách các trang web:
GET /feeds/site/domainName HTTP/1.1 Host: sites.google.com GData-Version: 1.4 Authorization: <your authorization header here> HTTP/1.1 200 OK <feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:gAcl="http://schemas.google.com/acl/2007" xmlns:sites="http://schemas.google.com/sites/2008" xmlns:gs="http://schemas.google.com/spreadsheets/2006" xmlns:dc="http://purl.org/dc/terms" xmlns:batch="http://schemas.google.com/gdata/batch" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0"> <id>https://sites.google.com/feeds/site/site</id> <updated>2009-12-02T17:47:34.406Z</updated> <title>Site</title> <link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="https://sites.google.com/feeds/site/site"/> <link rel="http://schemas.google.com/g/2005#post" type="application/atom+xml" href="https://sites.google.com/feeds/feeds/site/domainName"/> <link rel="self" type="application/atom+xml" href="https://sites.google.com/feeds/site/domainName"/> <link rel="next" type="application/atom+xml" href="https://sites.google.com/feeds/site/domainName/?start-index=2"/> <generator version="1" uri="http://sites.google.com/">Google Sites</generator> <openSearch:startIndex>1</openSearch:startIndex> <entry gd:etag="W/"CkUAQH4_eil7I2A9WxNaFk4.""> <id>https://sites.google.com/feeds/site/site/myTestSite</id> <updated>2009-12-01T01:17:21.042Z</updated> <app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-01T01:17:21.042Z</app:edited> <title>myTestSite</title> <summary/> <link rel="alternate" type="text/html" href="http://sites.google.com/site/myTestSite/"/> <link rel="http://schemas.google.com/acl/2007#accessControlList" type="application/atom+xml" href="https://sites.google.com/feeds/acl/site/domainName/myTestSite"/> <link rel="self" type="application/atom+xml" href="https://sites.google.com/feeds/site/domainName/myTestSite"/> <link rel="edit" type="application/atom+xml" href="https://sites.google.com/feeds/site/domainName/myTestSite"/> <sites:siteName>myTestSite</sites:siteName> <sites:theme>default</sites:theme> </entry> <entry gd:etag="W/"DkQGQHczfA9WxNaFk4.""> <id>https://sites.google.com/feeds/site/domainName/myOtherTestSite</id> <updated>2009-12-01T02:25:21.987Z</updated> <app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-01T02:25:21.987Z</app:edited> <title>myOtherTestSite</title> <summary>A new site to hold memories</summary> <category scheme="http://schemas.google.com/sites/2008#tag" term="Memories Site"/> <link rel="alternate" type="text/html" href="http://sites.google.com/site/myOtherTestSite"/> <link rel="http://schemas.google.com/acl/2007#accessControlList" type="application/atom+xml" href="https://sites.google.com/feeds/acl/site/domainName/myOtherTestSite"/> <link rel="self" type="application/atom+xml" href="https://sites.google.com/feeds/site/domainName/myOtherTestSite"/> <link rel="edit" type="application/atom+xml" href="https://sites.google.com/feeds/site/domainName/myOtherTestSite"/> <sites:siteName>myOtherTestSite</sites:siteName> <sites:theme>iceberg</sites:theme> </entry> ... </feed>
Các trang web được liệt kê theo thứ tự bảng chữ cái.
Tạo trang web mới
Lưu ý: Tính năng này chỉ được cung cấp cho các miền G Suite.
Bạn có thể cung cấp các trang web mới bằng cách tạo một HTTP POST cho nguồn cấp dữ liệu trang web, ví dụ:
POST /feeds/site/example.com HTTP/1.1 Host: sites.google.com GData-Version: 1.4 Authorization: <your authorization header here> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:sites="http://schemas.google.com/sites/2008"> <title>Source Site</title> <summary>A new site to hold memories</summary> <sites:theme>slate</sites:theme> </entry>
Yêu cầu trên sẽ tạo một Google Sites mới có giao diện "đá phiến" trong miền G Suite example.com.
URL của trang web sẽ là http://sites.google.com/a/example.com/source-site/.
Nếu tạo thành công trang web, máy chủ sẽ phản hồi bằng 201 Created.
Mục nhập phản hồi sẽ chứa các phần tử do máy chủ thêm, chẳng hạn như đường liên kết đến trang web, đường liên kết đến nguồn cấp dữ liệu ACL của trang web, tên trang web, tiêu đề và nội dung tóm tắt của trang web.
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gAcl="http://schemas.google.com/acl/2007"
xmlns:sites="http://schemas.google.com/sites/2008" xmlns:gs="http://schemas.google.com/spreadsheets/2006"
xmlns:dc="http://purl.org/dc/terms" xmlns:batch="http://schemas.google.com/gdata/batch"
xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0"
gd:etag="W/"DEECR38l7I2A9WxNaF0Q."">
<id>https://sites.google.com/feeds/site/example.com/source-site</id>
<updated>2009-12-02T23:31:06.184Z</updated>
<app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-02T23:31:06.184Z</app:edited>
<title>New Test Site</title>
<summary>A new site to hold memories</summary>
<link rel="alternate" type="text/html" href="http://sites.google.com/a/example.com/source-site/"/>
<link rel="http://schemas.google.com/acl/2007#accessControlList" type="application/atom+xml"
href="https://sites.google.com/feeds/acl/site/example.com/source-site"/>
<link rel="self" type="application/atom+xml" href="https://sites.google.com/feeds/site/example.com/source-site"/>
<link rel="edit" type="application/atom+xml" href="https://sites.google.com/feeds/site/example.com/source-site"/>
<sites:siteName>source-site</sites:siteName>
<sites:theme>slate</sites:theme>
</entry>
Sao chép trang web
Lưu ý: Tính năng này chỉ được cung cấp cho các miền G Suite.
Bạn có thể sao chép một trang web hiện có theo cách tương tự như khi tạo một trang web mới. Tuy nhiên, trong mục Atom của yêu cầu POST, hãy thêm một <link> có rel='source' trỏ đến nguồn cấp dữ liệu trang web của trang web cần sao chép. Mọi trang web đã được sao chép sẽ có đường liên kết này. Dưới đây là ví dụ về cách sao chép một trang web:
POST /feeds/site/example.com HTTP/1.1 Host: sites.google.com GData-Version: 1.4 Authorization: <your authorization header here> <entry xmlns="http://www.w3.org/2005/Atom"> <link rel="http://schemas.google.com/sites/2008#source" type="application/atom+xml" href="https://sites.google.com/feeds/site/example.com/source-site"/> <title>Copy of New Test Site</title> <summary>A newer site to hold memories</summary> </entry>
Yêu cầu trên sẽ sao chép trang web tại http://sites.google.com/a/example.com/source-site/.
Những điểm quan trọng:
- Bạn chỉ có thể sao chép những trang web và mẫu trang web mà người dùng đã xác thực sở hữu.
- Bạn cũng có thể sao chép mẫu trang web. Một trang web là mẫu nếu bạn đánh dấu vào chế độ cài đặt "Xuất bản trang web này dưới dạng mẫu" trong trang cài đặt của Google Sites.
- Bạn có thể sao chép một trang web từ một miền khác, miễn là bạn được liệt kê là chủ sở hữu trên trang web nguồn.
Cập nhật siêu dữ liệu của trang web
Để cập nhật tiêu đề hoặc nội dung tóm tắt của một trang web, hãy gửi một PUT HTTP đến đường liên kết edit của một mục nhập trang web.
Ví dụ: ví dụ sau đây sẽ cập nhật tiêu đề của trang web trước đó thành New Test Site2 và nội dung mô tả thành Newer description.
PUT /feeds/site/example.com/source-site HTTP/1.1 Host: sites.google.com GData-Version: 1.4 Authorization: <your authorization header here> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:gAcl="http://schemas.google.com/acl/2007" xmlns:sites="http://schemas.google.com/sites/2008" xmlns:gs="http://schemas.google.com/spreadsheets/2006" xmlns:dc="http://purl.org/dc/terms" xmlns:batch="http://schemas.google.com/gdata/batch" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" gd:etag="W/"DEECR38l7I2A9WxNaF0Q.""> <id>https://sites.google.com/feeds/site/example.com/source-site</id> <updated>2009-12-02T23:31:06.184Z</updated> <app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-02T23:31:06.184Z</app:edited> <title>New Test Site2</title> <summary>Newer description</summary> <category scheme="http://schemas.google.com/sites/2008#tag" term="Category"/> <link rel="alternate" type="text/html" href="http://sites.google.com/a/example.com/source-site/"/> <link rel="http://schemas.google.com/acl/2007#accessControlList" type="application/atom+xml" href="https://sites.google.com/feeds/acl/site/example.com/source-site"/> <link rel="self" type="application/atom+xml" href="https://sites.google.com/feeds/site/example.com/source-site"/> <link rel="edit" type="application/atom+xml" href="https://sites.google.com/feeds/site/example.com/source-site"/> <sites:siteName>source-site</sites:siteName> </entry>
Thêm danh mục
Lưu ý: Tính năng này chỉ được cung cấp cho các miền G Suite.
Các trang web G Suite cho miền của bạn có siêu dữ liệu danh mục hữu ích cho việc phân loại các trang web trong miền của bạn. Để thêm hoặc cập nhật siêu dữ liệu danh mục, hãy gửi một PUT HTTP đến đường liên kết edit của mục nhập trang web có chứa thẻ category. Hãy xem dòng chữ in đậm trong ví dụ sau:
PUT /feeds/site/example.com/source-site HTTP/1.1 Host: sites.google.com GData-Version: 1.4 Authorization: <your authorization header here> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:gAcl="http://schemas.google.com/acl/2007" xmlns:sites="http://schemas.google.com/sites/2008" xmlns:gs="http://schemas.google.com/spreadsheets/2006" xmlns:dc="http://purl.org/dc/terms" xmlns:batch="http://schemas.google.com/gdata/batch" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" gd:etag="W/"DEECR38l7I2A9WxNaF0Q.""> <id>https://sites.google.com/feeds/site/example.com/source-site</id> <updated>2009-12-02T23:31:06.184Z</updated> <app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-02T23:31:06.184Z</app:edited> <title>My Team website</title> <summary>This site contains contact information and a summary of major efforts our team owns</summary> <category scheme="http://schemas.google.com/sites/2008#tag" term="Team Site"/> <link rel="alternate" type="text/html" href="http://sites.google.com/a/example.com/my-team-site/"/> <link rel="http://schemas.google.com/acl/2007#accessControlList" type="application/atom+xml" href="https://sites.google.com/feeds/acl/site/example.com/my-team-site"/> <link rel="self" type="application/atom+xml" href="https://sites.google.com/feeds/site/example.com/my-team-site"/> <link rel="edit" type="application/atom+xml" href="https://sites.google.com/feeds/site/example.com/my-team-site"/> <sites:siteName>my-team-site</sites:siteName> </entry>
Ví dụ này chỉnh sửa một trang web hiện có và thêm danh mục "Trang web nhóm".
Bạn cũng có thể thêm nhiều danh mục bằng cách thêm các thẻ <category> khác. Hãy xem các dòng chữ in đậm trong ví dụ sau:
PUT /feeds/site/example.com/my-team-site HTTP/1.1 Host: sites.google.com GData-Version: 1.4 Authorization: <your authorization header here> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:gAcl="http://schemas.google.com/acl/2007" xmlns:sites="http://schemas.google.com/sites/2008" xmlns:gs="http://schemas.google.com/spreadsheets/2006" xmlns:dc="http://purl.org/dc/terms" xmlns:batch="http://schemas.google.com/gdata/batch" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" gd:etag="W/"DEECR38l7I2A9WxNaF0Q.""> <id>https://sites.google.com/feeds/site/example.com/my-team-site</id> <updated>2009-12-02T23:31:06.184Z</updated> <app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-02T23:31:06.184Z</app:edited> <title>My Team website</title> <summary>This site contains contact information and a summary of major efforts our team owns</summary> <category scheme="http://schemas.google.com/sites/2008#tag" term="Team Site/"> <category scheme="http://schemas.google.com/sites/2008#tag" term="Legal Department/"> <link rel="alternate" type="text/html" href="http://sites.google.com/a/example.com/my-team-site/"/> <link rel="http://schemas.google.com/acl/2007#accessControlList" type="application/atom+xml" href="https://sites.google.com/feeds/acl/site/example.com/my-team-site"/> <link rel="self" type="application/atom+xml" href="https://sites.google.com/feeds/site/example.com/my-team-site"/> <link rel="edit" type="application/atom+xml" href="https://sites.google.com/feeds/site/example.com/my-team-site"/> <sites:siteName>my-team-site</sites:siteName> </entry>
Ví dụ này thêm hai danh mục: "Trang web nhóm" và "Phòng pháp lý"
Ánh xạ địa chỉ web
Tính năng liên kết địa chỉ web cho phép người dùng Sites liên kết miền của riêng họ với một trang web trên Google Sites. Ví dụ: bạn có thể dùng http://www.mydomainsite.com thay vì http://sites.google.com/a/domain.com/mysite. Tuỳ thuộc vào nơi lưu trữ trang web của bạn, bạn có thể sửa đổi các mối liên kết giữa địa chỉ web của trang web theo cách thủ công. Xem bài viết trên trung tâm trợ giúp của chúng tôi để biết thêm thông tin.
Tìm nạp các mối liên kết địa chỉ web của một trang web
Để trả về các mối liên kết địa chỉ web cho một trang web, hãy tìm nạp mục/nguồn cấp dữ liệu của trang web bằng tham số with-mappings=true:
GET /feeds/site/domainName?with-mappings=true HTTP/1.1 Host: sites.google.com GData-Version: 1.4 Authorization: <your authorization header here> HTTP/1.1 200 OK <feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:gAcl="http://schemas.google.com/acl/2007" xmlns:sites="http://schemas.google.com/sites/2008" xmlns:gs="http://schemas.google.com/spreadsheets/2006" xmlns:dc="http://purl.org/dc/terms" xmlns:batch="http://schemas.google.com/gdata/batch" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0"> ... <entry gd:etag="W/"DkQGQHczfA9WxNaFk4.""> <id>https://sites.google.com/feeds/site/domainName/myOtherTestSite</id> <updated>2009-12-01T02:25:21.987Z</updated> <app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-01T02:25:21.987Z</app:edited> <title>myOtherTestSite</title> <summary>A new site to hold memories</summary> <link rel="alternate" type="text/html" href="http://sites.google.com/site/myOtherTestSite"/> <link rel="http://schemas.google.com/acl/2007#accessControlList" type="application/atom+xml" href="https://sites.google.com/feeds/acl/site/domainName/myOtherTestSite"/> <link rel="self" type="application/atom+xml" href="https://sites.google.com/feeds/site/domainName/myOtherTestSite"/> <link rel="edit" type="application/atom+xml" href="https://sites.google.com/feeds/site/domainName/myOtherTestSite"/> <link rel='webAddressMapping' href='http://www.mysitemapping.com'> <link rel='webAddressMapping' href='http://www.mysitemapping2.com'> <link rel='webAddressMapping' href='http://www.myothermapping.org'> </entry> ... </feed>
Các mối liên kết hiện có sẽ xuất hiện dưới dạng link có rel="webAddressMapping". Ví dụ: trong ví dụ trên, có 3 webAddressMapping trỏ đến trang web http://sites.google.com/site/myOtherTestSite.
Sửa đổi ánh xạ địa chỉ web
Lưu ý: Tất cả các thao tác GET/POST/PUT đều phải chỉ định tham số with-mappings=true khi làm việc với các mối liên kết địa chỉ web. Nếu thiếu tham số này, webAddressMapping sẽ không được trả về trong các mục trang web (GET) hoặc được xem xét khi cập nhật/xoá (PUT) các mối liên kết khỏi một mục.
Để thêm, cập nhật hoặc xoá một mối liên kết, bạn chỉ cần chỉ định, thay đổi hoặc xoá mối liên kết đó khi tạo trang web mới hoặc cập nhật siêu dữ liệu của một trang web. Bạn phải thêm tham số with-mappings=true vào URI nguồn cấp dữ liệu trang web.
Lưu ý: để cập nhật thông tin ánh xạ địa chỉ, bạn cần phải là quản trị viên trang web hoặc quản trị viên miền trong trường hợp trang web được lưu trữ trên G Suite.
Ví dụ: yêu cầu bên dưới sẽ cập nhật mối liên kết http://www.mysitemapping.com thành http://www.my-new-sitemapping.com và xoá http://www.mysitemapping2.com bằng cách loại bỏ mối liên kết khỏi mục nhập:
PUT /feeds/site/domainName?with-mappings=true HTTP/1.1 Host: sites.google.com GData-Version: 1.4 Authorization: <your authorization header here> <entry gd:etag="W/"DkQGQHczfA9WxNaFk4.""> <id>https://sites.google.com/feeds/site/domainName/myOtherTestSite</id> <updated>2009-12-01T02:25:21.987Z</updated> <app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-01T02:25:21.987Z</app:edited> <title>myOtherTestSite</title> <summary>A new site to hold memories</summary> <link rel="alternate" type="text/html" href="http://sites.google.com/site/myOtherTestSite"/> <link rel="http://schemas.google.com/acl/2007#accessControlList" type="application/atom+xml" href="https://sites.google.com/feeds/acl/site/domainName/myOtherTestSite"/> <link rel="self" type="application/atom+xml" href="https://sites.google.com/feeds/site/domainName/myOtherTestSite"/> <link rel="edit" type="application/atom+xml" href="https://sites.google.com/feeds/site/domainName/myOtherTestSite"/> <link rel='webAddressMapping' href='www.my-new-sitemapping.com'> <!-- missing mapping2 will be deleted --> <link rel='webAddressMapping' href='http://www.myothermapping.org'> </entry>
Xin lưu ý rằng bạn cũng có thể chỉ định mối liên kết giữa địa chỉ web tại thời điểm tạo/sao chép một trang web.
Danh sách hoạt động
Bạn có thể tìm nạp hoạt động (thay đổi) gần đây của một Trang web bằng cách tìm nạp nguồn cấp dữ liệu hoạt động. Mỗi mục trong nguồn cấp dữ liệu hoạt động đều chứa thông tin về một thay đổi được thực hiện đối với Trang web.
Để truy vấn bảng tin hoạt động, hãy gửi một GET HTTP đến URL bảng tin hoạt động:
https://sites.google.com/feeds/activity/domainName/siteName
| Tham số nguồn cấp dữ liệu | Mô tả |
|---|---|
domainName | "site" hoặc miền của tên miền được lưu trữ trên G Suite (ví dụ: example.com). |
siteName | Tên không gian trên web của trang web; có trong URL của trang web (ví dụ: myCoolSite). |
Ví dụ về yêu cầu và phản hồi:
GET /feeds/activity/site/siteName HTTP/1.1 Host: sites.google.com GData-Version: 1.4 Authorization: <your authorization header here> HTTP/1.1 200 OK <?xml version="1.0" encoding="UTF-8"?> <feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/"> <id>https://sites.google.com/feeds/activity/site/siteName</id> <updated>2009-09-10T05:24:23.120Z</updated> <title>Activity</title> <link rel="alternate" type="text/html" href="http://sites.google.com/site/siteName/system/app/pages/recentChanges"/> <link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="https://sites.google.com/feeds/activity/site/siteName"/> <link rel="self" type="application/atom+xml" href="https://sites.google.com/feeds/activity/site/siteName"/> <generator version="1" uri="http://sites.google.com">Google Sites</generator> <openSearch:startIndex>1</openSearch:startIndex> <entry xmlns:gd="http://schemas.google.com/g/2005" gd:etag="W/"CU4GQ3szfSl7ImA9WxNRFUg.""> <id>https://sites.google.com/feeds/activity/site/siteName/940375996952876062</id> <updated>2009-09-10T03:38:42.585Z</updated> <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/sites/2008#deletion" label="deletion"/> <title>home</title> <summary type="xhtml"> <div xmlns="http://www.w3.org/1999/xhtml">User deleted <a href="http://sites.google.com/site/siteName/home">home</a> </div> </summary> <link rel="http://schemas.google.com/sites/2008#revision" type="application/atom+xml" href="https://sites.google.com/feeds/revision/site/siteName/5409745539831916487"/> <link rel="http://schemas.google.com/sites/2008#current" type="application/atom+xml" href="https://sites.google.com/feeds/content/site/siteName/5409745539831916487"/> <link rel="self" type="application/atom+xml" href="https://sites.google.com/feeds/activity/site/siteName/940375996952876062"/> <author> <name>User</name> <email>user@gmail.com</email> </author> </entry> <entry xmlns:gd="http://schemas.google.com/g/2005" gd:etag="W/"CU8DQn45fyl7ImA9WxNRFUg.""> <id>https://sites.google.com/feeds/activity/site/siteName/7165439066235480082</id> <updated>2009-09-10T03:37:53.027Z</updated> <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/sites/2008#edit" label="edit"/> <title>home</title> <summary type="xhtml"> <div xmlns="http://www.w3.org/1999/xhtml">User2 edited <a href="http://sites.google.com/site/siteName/home">home</a> </div> </summary> <link rel="http://schemas.google.com/sites/2008#revision" type="application/atom+xml" href="https://sites.google.com/feeds/revision/site/siteName/5409745539831916487"/> <link rel="http://schemas.google.com/sites/2008#current" type="application/atom+xml" href="https://sites.google.com/feeds/content/site/siteName/5409745539831916487"/> <link rel="self" type="application/atom+xml" href="https://sites.google.com/feeds/activity/site/siteName/7165439066235480082"/> <author> <name>User</name> <email>user@gmail.com</email> </author> </entry> <entry xmlns:gd="http://schemas.google.com/g/2005" gd:etag="W/"CU8AR3s4cSl7ImA9WxNRFUg.""> <id>https://sites.google.com/feeds/activity/site/siteName/127448462987345884</id> <updated>2009-09-10T03:37:26.539Z</updated> <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/sites/2008#creation" label="creation"/> <title>home</title> <summary type="xhtml"> <div xmlns="http://www.w3.org/1999/xhtml">User3 created <a href="http://sites.google.com/site/siteName/home">home</a> </div> </summary> <link rel="http://schemas.google.com/sites/2008#revision" type="application/atom+xml" href="https://sites.google.com/feeds/revision/site/siteName/5409745539831916487"/> <link rel="http://schemas.google.com/sites/2008#current" type="application/atom+xml" href="https://sites.google.com/feeds/content/site/siteName/5409745539831916487"/> <link rel="self" type="application/atom+xml" href="https://sites.google.com/feeds/activity/site/siteName/127448462987345884"/> <author> <name>User3</name> <email>user3@gmail.com</email> </author> </entry> </feed>
Lưu ý: Bạn phải là cộng tác viên hoặc chủ sở hữu của Trang web thì mới có quyền truy cập vào nguồn cấp dữ liệu này.
Ứng dụng phải gửi tiêu đề Authorization chính xác và tham chiếu đến mã thông báo nhận được trong phần Uỷ quyền yêu cầu.
Nguồn cấp dữ liệu bản sửa đổi
Để tìm nạp nhật ký sửa đổi cho bất kỳ mục nội dung nào, hãy gửi một HTTP GET đến đường liên kết sửa đổi của mục đó:
https://sites.google.com/feeds/revision/domainName/siteName/CONTENT_ENTRY_ID
| Tham số nguồn cấp dữ liệu | Mô tả |
|---|---|
domainName | "site" hoặc miền của tên miền được lưu trữ trên G Suite (ví dụ: example.com). |
siteName | Tên không gian trên web của trang web; có trong URL của trang web (ví dụ: myCoolSite). |
Để tìm đường liên kết đến bản sửa đổi cho một trang/bình luận/tệp đính kèm/mục danh sách nhất định, trước tiên, hãy truy xuất mục đó từ nguồn cấp nội dung bằng CONTENT_ENTRY_ID. Mục đã truy xuất sẽ chứa một <atom:link> cho nguồn cấp dữ liệu bản sửa đổi.
Ví dụ:
<link rel="http://schemas.google.com/sites/2008#revision" type="application/atom+xml"
href="https://sites.google.com/feeds/revision/domainName/siteName/CONTENT_ENTRY_ID"/>
Ví dụ về yêu cầu và phản hồi:
GET /feeds/revision/domainName/siteName/CONTENT_ENTRY_ID HTTP/1.1 Host: sites.google.com GData-Version: 1.4 Authorization: <your authorization header here> HTTP/1.1 200 OK <?xml version="1.0" encoding="UTF-8"?> <feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:sites="http://schemas.google.com/sites/2008" xmlns:gs="http://schemas.google.com/spreadsheets/2006" xmlns:dc="http://purl.org/dc/terms" xmlns:batch="http://schemas.google.com/gdata/batch" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0"> <id>https://sites.google.com/feeds/revision/domainName/siteName/CONTENT_ENTRY_ID</id> <updated>2009-09-10T04:33:35.337Z</updated> <title>Revisions</title> <link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="https://sites.google.com/feeds/revision/domainName/siteName/CONTENT_ENTRY_ID"/> <link rel="self" type="application/atom+xml" href="https://sites.google.com/feeds/revision/domainName/siteName/CONTENT_ENTRY_ID"/> <generator version="1" uri="http://sites.google.com">Google Sites</generator> <openSearch:startIndex>1</openSearch:startIndex> <entry gd:etag="W/"CU4GQmA9WxNRFUg.""> <id>https://sites.google.com/feeds/revision/domainName/siteName/CONTENT_ENTRY_ID/2</id> <updated>2009-09-10T03:38:42.045Z</updated> <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/sites/2008#webpage" label="webpage"/> <title>Home</title> <content type="xhtml"> <div xmlns="http://www.w3.org/1999/xhtml">Latest content here</div> </content> <link rel="alternate" type="text/html" href="http://sites.google.com/domainName/siteName/CONTENT_ENTRY_ID/system/app/pages/admin/compare?wuid=wuid%3Agx%3A4f67c7&rev1=2"/> <link rel="self" type="application/atom+xml" href="https://sites.google.com/feeds/revision/domainName/siteName/CONTENT_ENTRY_ID/2"/> <author> <name>User</name> <email>user@gmail.com</email> </author> <sites:pageName>home</sites:pageName> <sites:revision>2</sites:revision> </entry> <entry gd:etag="W/"CU8DQ388eSl7ImA9WxNRFUg.""> <id>https://sites.google.com/feeds/revision/domainName/siteName/CONTENT_ENTRY_ID/1</id> <updated>2009-09-10T03:37:52.171Z</updated> <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/sites/2008#webpage" label="webpage"/> <title>Home</title> <content type="xhtml"> <div xmlns="http://www.w3.org/1999/xhtml">Older content here</div> </content> <link rel="alternate" type="text/html" href="http://sites.google.com/domainName/siteName/CONTENT_ENTRY_ID/system/app/pages/admin/compare?wuid=wuid%3Agx%3A4bc7&rev1=1"/> <link rel="self" type="application/atom+xml" href="https://sites.google.com/feeds/revision/domainName/siteName/CONTENT_ENTRY_ID/1"/> <author> <name>User</name> <email>user@gmail.com</email> </author> <sites:pageName>home</sites:pageName> <sites:revision>1</sites:revision> </entry> </feed>
Lưu ý: Bạn phải là cộng tác viên hoặc chủ sở hữu của Trang web thì mới có quyền truy cập vào nguồn cấp dữ liệu này.
Ứng dụng của bạn phải gửi tiêu đề Authorization chính xác và tham chiếu đến mã thông báo nhận được trong phần Uỷ quyền yêu cầu.
Nguồn cấp dữ liệu nội dung
Truy xuất nội dung
Nguồn cấp nội dung liệt kê nội dung hiện tại của một trang web. Gửi yêu cầu GET đã xác thực đến URL sau:
https://sites.google.com/feeds/content/domainName/siteName
| Tham số nguồn cấp dữ liệu | Mô tả |
|---|---|
domainName | "site" hoặc miền của tên miền được lưu trữ trên G Suite (ví dụ: example.com). |
siteName | Tên không gian trên web của trang web; có trong URL của trang web (ví dụ: myCoolSite). |
Kết quả là một nguồn cấp dữ liệu liệt kê trang đầu tiên của các mục nội dung trên Trang web. Mỗi mục trong nguồn cấp dữ liệu sẽ đại diện cho một loại mục nội dung, chẳng hạn như webpage, filecabinet, attachment, comment, v.v. Phần tử <category scheme="http://schemas.google.com/g/2005#kind"> xác định loại mục. Hãy xem hướng dẫn tham khảo để biết danh sách các giá trị kind được hỗ trợ.
Lưu ý: Nguồn cấp dữ liệu này có thể yêu cầu hoặc không yêu cầu xác thực, tuỳ thuộc vào quyền chia sẻ của Trang web.
Nếu Trang web không phải là trang web công khai, thì ứng dụng của bạn phải gửi tiêu đề Authorization chính xác (như trong ví dụ ở trên) và tham chiếu đến mã thông báo nhận được trong phần Uỷ quyền yêu cầu.
GET /feeds/content/domainName/siteName HTTP/1.1 Host: sites.google.com GData-Version: 1.4 Authorization: <your authorization header here> HTTP/1.1 200 OK <?xml version="1.0" encoding="UTF-8"?> <feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:sites="http://schemas.google.com/sites/2008" xmlns:gs="http://schemas.google.com/spreadsheets/2006" xmlns:dc="http://purl.org/dc/terms" xmlns:batch="http://schemas.google.com/gdata/batch" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0"> <id>https://sites.google.com/feeds/content/domainName/siteName</id> <updated>2009-08-31T01:39:20.286Z</updated> <title>Content</title> <link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="https://sites.google.com/feeds/content/domainName/siteName"/> <link rel="http://schemas.google.com/g/2005#post" type="application/atom+xml" href="https://sites.google.com/feeds/content/domainName/siteName"/> <link rel="self" type="application/atom+xml" href="https://sites.google.com/feeds/content/domainName/siteName"/> <link rel="http://schemas.google.com/g/2005#batch" type="application/atom+xml" href="https://sites.google.com/feeds/content/domainName/siteName/batch""/> <link rel="next" type="application/atom+xml" href="https://sites.google.com/feeds/content/domainName/siteName/?start-index=2"/> <generator version="1" uri="http://sites.google.com">Google Sites</generator> <openSearch:startIndex>1</openSearch:startIndex> <entry gd:etag="W/"Ck8GQXk7fil7ImA9WxNSFk0.""> <id>https://sites.google.com/feeds/content/domainName/siteName/7322156894</id> <updated>2009-08-30T02:53:40.706Z</updated> <app:edited xmlns:app="http://www.w3.org/2007/app">2009-08-30T02:53:40.706Z</app:edited> <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/sites/2008#webpage" label="webpage"/> <title>Subpage</title> <content type="xhtml"> <div xmlns="http://www.w3.org/1999/xhtml">Page html content here</div> </content> <link rel="http://schemas.google.com/sites/2008#parent" type="application/atom+xml" href="https://sites.google.com/feeds/content/domainName/siteName/6492205817"/> <link rel="alternate" type="text" href="http://sites.google.com/site/siteName/subpage"/> <link rel="http://schemas.google.com/sites/2008#revision" type="application/atom+xml" href="https://sites.google.com/feeds/revision/domainName/siteName/7322156894"/> <link rel="self" type="application/atom+xml" href="https://sites.google.com/feeds/content/domainName/siteName/7322156894"/> <link rel="edit" type="application/atom+xml" href="https://sites.google.com/feeds/content/domainName/siteName/7322156894"/> <author> <name>User</name> <email>user@gmail.com</email> </author> <sites:pageName>subpage</sites:pageName> <sites:revision>5</sites:revision> </entry> <entry gd:etag="W/"CkMBQH08fCl7ImA9WxNSFk0.""> <id>https://sites.google.com/feeds/content/domainName/siteName/5930635231</id> <updated>2009-08-30T02:47:31.374Z</updated> <app:edited xmlns:app="http://www.w3.org/2007/app">2009-08-30T02:47:31.374Z</app:edited> <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/sites/2008#listitem" label="listpage"/> <title/> <link rel="http://schemas.google.com/sites/2008#parent" type="application/atom+xml" href="https://sites.google.com/feeds/content/domainName/siteName/5930635231"/> <link rel="http://schemas.google.com/sites/2008#revision" type="application/atom+xml" href="https://sites.google.com/feeds/revision/domainName/siteName/5930635231"/> <link rel="self" type="application/atom+xml" href="https://sites.google.com/feeds/content/domainName/siteName/5930635231"/> <link rel="edit" type="application/atom+xml" href="https://sites.google.com/feeds/content/domainName/siteName/5930635231"/> <author> <name>User</name> <email>user@gmail.com</email> </author> <sites:revision>1</sites:revision> <gs:field index="A" name="Issue/Feature">Implement cool feature X</gs:field> <gs:field index="B" name="Priority">P2</gs:field> <gs:field index="C" name="Owner"/> <gs:field index="D" name="Resolved"/> </entry> <entry gd:etag="W/"AkYHQ3ozcCl7ImA9WxJaE08.""> <id>https://sites.google.com/feeds/content/domainName/siteName/1265948545471894517</id> <updated>2009-08-03T19:35:32.488Z</updated> <app:edited xmlns:app="http://www.w3.org/2007/app">2009-08-03T19:35:32.488Z</app:edited> <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/sites/2008#filecabinet" label="filecabinet"/> <title>files</title> <content type="xhtml"> <div xmlns="http://www.w3.org/1999/xhtml">Page html content here</div> </content> <link rel="alternate" type="text" href="https://sites.google.com/domainName/siteName/files"/> <link rel="http://schemas.google.com/sites/2008#revision" type="application/atom+xml" href="https://sites.google.com/feeds/revision/domainName/siteName/12671894517"/> <link rel="self" type="application/atom+xml" href="https://sites.google.com/feeds/content/domainName/siteName/12671894517"/> <link rel="edit" type="application/atom+xml" href="https://sites.google.com/feeds/content/domainName/siteName/12671894517"/> <author> <name>User</name> <email>user@gmail.com</email> </author> <gd:feedLink href="httpn://sites.google.com/feeds/content/domainName/siteName?parent=12671894517"/> <sites:pageName>files</sites:pageName> <sites:revision>1</sites:revision> </entry> ... </feed>
Lưu ý: Đây chỉ là một vài kết quả đầu tiên. Để chuyển trang qua toàn bộ nguồn cấp nội dung, hãy làm theo đường liên kết "tiếp theo" của nguồn cấp dữ liệu:
<link rel="next" type="application/atom+xml" href="https://sites.google.com/feeds/content/domainName/siteName/?start-index=2"/>
Để biết nội dung giải thích về các phần tử phổ biến đối với Atom, hãy xem tài liệu tham khảo về Giao thức dữ liệu của Google.
Các phần tử có ý nghĩa cụ thể đối với API Sites cũ được mô tả bên dưới. Một số mục loại sẽ có các thuộc tính bổ sung (không được liệt kê bên dưới), trong khi những mục khác thì không. Ví dụ: mục nhập listitem có thể có các phần tử <gs:field>, trong khi mục nhập webpage thì không.
| Phần tử | Mô tả |
|---|---|
<content ...> | Văn bản bên trong là nội dung HTML của trang. Đối với một số mục (ví dụ: tệp đính kèm), phần tử này sẽ chứa một thuộc tính src trỏ đến tệp. |
<link rel="alternate" ...> | Đường liên kết đến trang hoặc mục trong Google Sites. |
<link rel="http://schemas.google.com/sites/2008#revision" ...> | Thuộc tính href trỏ đến nguồn cấp dữ liệu sửa đổi của mục nhập. |
<link rel="http://schemas.google.com/sites/2008#parent" ...> | Thuộc tính href trỏ đến mục nhập mẹ của mục nhập. |
<link rel="http://schemas.google.com/sites/2008#template" ...> | Thuộc tính href trỏ đến trang mẫu của mục. |
<category scheme="http://schemas.google.com/g/2005#kind" ...> | label là loại mục nhập. |
<category term="http://schemas.google.com/g/2005#template" ...> | label=template cho biết mục nhập là một mẫu. |
<gd:feedLink> | Thuộc tính href trỏ đến các phần tử con của phần tử mẹ của mục nhập. |
<sites:pageName> | Tên không gian web của trang; tương ứng với tên trong URL của trang. |
<sites:revision> | Số phiên bản hiện tại. |
Ví dụ về truy vấn nguồn cấp nội dung
Bạn có thể tìm kiếm trong nguồn cấp nội dung bằng cách sử dụng một số tham số truy vấn Google Data API tiêu chuẩn và những tham số dành riêng cho API Sites cũ. Để biết thêm thông tin chi tiết và danh sách đầy đủ các thông số được hỗ trợ, hãy xem Hướng dẫn tham khảo.
Truy xuất các loại mục cụ thể
Để chỉ tìm nạp một loại mục cụ thể, hãy sử dụng tham số kind. Ví dụ này chỉ trả về các mục webpage:
GET /feeds/content/domainName/siteName?kind=webpage
Để trả về nhiều loại mục nhập, hãy phân tách từng kind bằng dấu ",". Ví dụ này trả về các mục nhập filecabinet và listpage:
GET /feeds/content/domainName/siteName?kind=filecabinet,listpage
Ngoài ra, bạn có thể sử dụng định dạng chuẩn cho một truy vấn /-/category của Google Data thay vì tham số kind:
GET /feeds/content/domainName/siteName/-/filecabinet|listpage
Truy xuất mẫu trang
Ví dụ này chỉ trả về các trang template:
GET /feeds/content/domainName/siteName/-/template
Để trả về tất cả các loại mục nhập và bao gồm các trang template, hãy sử dụng:
GET /feeds/content/domainName/siteName/-/template|-template
Truy xuất một trang theo đường dẫn
Nếu biết đường dẫn tương đối của một trang trong Google Sites, bạn có thể dùng tham số path để tìm nạp trang cụ thể đó.
Ví dụ này sẽ trả về trang nằm tại http://sites.google.com/site/siteName/path/to/the/page:
GET /feeds/content/domainName/siteName?path=/path/to/the/page
Truy xuất tất cả các mục trong một trang mẹ
Nếu biết mã nhận dạng mục của một trang, bạn có thể dùng tham số parent để tìm nạp tất cả các mục con của trang đó (nếu có):
GET /feeds/content/domainName/siteName?parent=CONTENT_ENTRY_ID
Bao gồm các mục nháp hoặc mục đã xoá
Để thêm các mục nháp hoặc mục đã xoá, hãy dùng các tham số include-drafts hoặc include-deleted tương ứng.
Ví dụ này bao gồm các mục nháp trong nguồn cấp nội dung:
GET /feeds/content/domainName/siteName?include-drafts=true
Tìm kiếm toàn bộ văn bản
Để tìm kiếm trên toàn bộ nội dung của một trang web, hãy dùng tham số q để đưa ra một cụm từ tìm kiếm toàn văn:
GET /feeds/content/domainName/siteName?q=Text%20I%20am%20looking%20for
Tạo nội dung
Bạn có thể tạo nội dung mới (trang web, trang danh sách, trang tủ hồ sơ, trang thông báo, v.v.) bằng cách gửi một HTTP POST đến nguồn cấp nội dung:
https://sites.google.com/feeds/content/domainName/siteName
Để biết danh sách các loại mục được hỗ trợ, hãy xem tham số kind trong Hướng dẫn tham khảo.
Tạo mục / trang mới
Ví dụ này tạo một webpage mới trong cấp cao nhất của Trang web, bao gồm một số XHTML cho nội dung trang và đặt tiêu đề của tiêu đề thành "Tiêu đề trang web mới":
POST /feeds/content/domainName/siteName HTTP/1.1 Host: sites.google.com GData-Version: 1.4 Authorization: <your authorization header here> Content-Length: 328 Content-Type: application/atom+xml <entry xmlns="http://www.w3.org/2005/Atom"> <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/sites/2008#webpage" label="webpage"/> <title>New Webpage Title</title> <content type="xhtml"> <div xmlns="http://www.w3.org/1999/xhtml">HTML body goes here</div> </content> </entry>
Nếu thành công, máy chủ sẽ phản hồi bằng 201 Created và một bản sao của mục nhập.
Tạo các mục/trang trong đường dẫn URL tuỳ chỉnh
Theo mặc định, ví dụ trước sẽ được tạo trong URL http://sites.google.com/domainName/siteName/new-webpage-title và có tiêu đề trang là "Tiêu đề trang web mới". Tức là <atom:title> được chuẩn hoá thành new-webpage-title cho URL.
Để tuỳ chỉnh đường dẫn URL của một trang, bạn có thể đặt phần tử <sites:pageName>.
Ví dụ này tạo một filecabinet mới có tiêu đề trang là "Lưu trữ tệp", nhưng tạo trang trong URL http://sites.google.com/domainName/siteName/files bằng cách chỉ định phần tử <sites:pageName>.
POST /feeds/content/domainName/siteName HTTP/1.1 Host: sites.google.com GData-Version: 1.4 Authorization: <your authorization header here> Content-Length: 393 Content-Type: application/atom+xml <entry xmlns="http://www.w3.org/2005/Atom" xmlns:sites="http://schemas.google.com/sites/2008"> <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/sites/2008#filecabinet" label="filecabinet"/> <title>File Storage</title> <content type="xhtml"> <div xmlns="http://www.w3.org/1999/xhtml">A list of files is below.</div> </content> <sites:pageName>files</sites:pageName> </entry>
Máy chủ sử dụng các quy tắc ưu tiên sau đây để đặt tên cho đường dẫn URL của trang:
<sites:pageName>, nếu có. Phải đáp ứnga-z, A-Z, 0-9, -, _.<atom:title>không được có giá trị rỗng nếu không có pageName. Chuẩn hoá là cắt + thu gọn khoảng trắng thành "-" và xoá các ký tự không khớp vớia-z, A-Z, 0-9, -, _.
Ví dụ: "Custom_Page2" sẽ được máy chủ chấp nhận.
Tạo trang con
Để tạo trang con trong một trang mẹ, hãy thêm một <link rel="http://schemas.google.com/sites/2008#parent"> vào mục Atom mới. Đặt thuộc tính href của đường liên kết thành đường liên kết tự tham chiếu của mục nhập mẹ.
Ví dụ này tạo một announcement mới có tiêu đề "thông báo", trong một trang thông báo chính có mã nhận dạng mục nhập PARENT_ENTRY_ID. Nội dung XHTML cho phần nội dung trang cũng được đưa vào:
POST /feeds/content/domainName/siteName HTTP/1.1 Host: sites.google.com GData-Version: 1.4 Authorization: <your authorization header here> Content-Length: 470 Content-Type: application/atom+xml <entry xmlns="http://www.w3.org/2005/Atom"> <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/sites/2008#announcement" label="announcement"/> <link rel="http://schemas.google.com/sites/2008#parent" type="application/atom+xml" href="https://sites.google.com/feeds/content/domainName/siteName/PARENT_ENTRY_ID"/> <title>announcement</title> <content type="xhtml"> <div xmlns="http://www.w3.org/1999/xhtml">This weekend. My place.</div> </content> </entry>
Mẫu trang
Tạo mẫu trang
Quy trình tạo mẫu trang giống với quy trình tạo các mục/trang mới và tạo trang con.Điểm khác biệt là việc thêm category với cụm từ và nhãn được đặt thành "http://schemas.google.com/g/2005#template" và "template" (mẫu) tương ứng.
Ví dụ này tạo một mẫu webpage mới.
POST /feeds/content/domainName/siteName HTTP/1.1 Host: sites.google.com GData-Version: 1.4 Authorization: <your authorization header here> Content-Length: 464 Content-Type: application/atom+xml <entry xmlns="http://www.w3.org/2005/Atom" xmlns:sites="http://schemas.google.com/sites/2008"> <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/sites/2008#webpage" label="webpage"/> <category scheme="http://schemas.google.com/g/2005#labels" term="http://schemas.google.com/g/2005#template" label="template"/> <title>Webpage Template</title> <content type="xhtml"> <div xmlns="http://www.w3.org/1999/xhtml">This weekend. My place.</div> </content> </entry>
Tạo trang từ mẫu
Tương tự như việc tạo mẫu trang, bạn có thể tạo thực thể một trang mới từ mẫu bằng cách thêm một <link> có rel='http://schemas.google.com/sites/2008#template' trỏ đến tự liên kết của một mẫu trang.
Ví dụ này tạo một trang filecabinet mới từ một mẫu trang hiện có xác định một tủ đựng hồ sơ.
POST /feeds/content/domainName/siteName HTTP/1.1 Host: sites.google.com GData-Version: 1.4 Authorization: <your authorization header here> Content-Length: 464 Content-Type: application/atom+xml <entry xmlns="http://www.w3.org/2005/Atom" xmlns:sites="http://schemas.google.com/sites/2008"> <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/sites/2008#filecabinet" label="filecabinet"/> <title>File Cabinet Page From Template</title> <link rel='http://schemas.google.com/sites/2008#template' type='application/atom+xml' href='https://sites.google.com/feeds/content/domainName/siteName/ENTRY_ID'/> </entry>
Lưu ý: Mặc dù mẫu xác định một <category>, nhưng bạn vẫn phải thêm một <category> vào mục nhập của mình. Ngoài ra, xin lưu ý rằng nếu bạn thêm một phần tử <content>, thì máy chủ sẽ từ chối phần tử đó.
Đang tải tệp lên
Giống như trong Google Sites, API này cho phép bạn tải tệp đính kèm lên các trang tổ chức tệp và trang mẹ.
Để tải tệp đính kèm lên một phần tử mẹ, hãy gửi yêu cầu HTTP POST đến URL nguồn cấp nội dung:
https://sites.google.com/feeds/content/domainName/siteName
Nội dung POST phải là một yêu cầu nhiều phần theo MIME để kết hợp nội dung tệp với <atom:entry> chứa siêu dữ liệu của tệp đính kèm. <atom:entry> phải tham chiếu đến đường liên kết tự liên kết của mục nhập mẹ để chỉ định nơi tệp đính kèm sẽ được tạo.
Hãy xem phần Tạo trang con để biết thêm thông tin.
Đang tải tệp đính kèm lên
Sau đây là ví dụ về cách tải một tệp PDF lên trang tổ chức tệp có mã nhận dạng PARENT_ENTRY_ID. Tệp đính kèm sẽ được tạo với tiêu đề "Tệp PDF" và nội dung mô tả (không bắt buộc) là "Gói tài liệu về nhân sự".
POST /feeds/content/domainName/siteName HTTP/1.1 Host: sites.google.com GData-Version: 1.4 Authorization: <your authorization header here> Content-Length: 7221984 Content-Type: multipart/related; boundary=END_OF_PART --END_OF_PART Content-Type: application/atom+xml <entry xmlns="http://www.w3.org/2005/Atom"> <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/sites/2008#attachment" label="attachment"/> <link rel="http://schemas.google.com/sites/2008#parent" type="application/atom+xml" href="https://sites.google.com/feeds/content/domainName/siteName/PARENT_ENTRY_ID"/> <title>PDF File</title> <summary>HR packet</summary> </entry> --END_OF_PART Content-Type: application/pdf ... pdf contents here ... --END_OF_PART--
Nếu quá trình tải lên thành công, máy chủ sẽ phản hồi bằng 201 Created và một bản sao của mục tệp đính kèm mới tạo.
Tải tệp đính kèm lên một thư mục
Để tải tệp đính kèm lên một thư mục hiện có trong filecabinet, hãy thêm một danh mục có thuộc tính "term" được đặt thành tên của thư mục:
<category scheme="http://schemas.google.com/sites/2008#folder" term="FolderName">Tệp đính kèm trên web
Tệp đính kèm trên web là một loại tệp đính kèm đặc biệt. Về cơ bản, đó là các đường liên kết đến những tệp khác trên web mà bạn có thể thêm vào danh sách tủ hồ sơ. Tính năng này tương tự như phương thức tải lên "Thêm tệp bằng URL" trong giao diện người dùng của Google Sites.
Lưu ý: Bạn chỉ có thể tạo tệp đính kèm trên web trong trang tổ chức tệp. Bạn không thể tải các tệp này lên các loại trang khác.
Ví dụ này tạo một webattachment trong tủ đựng hồ sơ được tham chiếu theo mã nhận dạng FILECABINET_ENTRY_ID.
Tiêu đề và nội dung mô tả (không bắt buộc) của biểu tượng này được đặt lần lượt là "GoogleLogo" và "nice colors".
POST /feeds/content/domainName/siteName HTTP/1.1 Host: sites.google.com GData-Version: 1.4 Authorization: <your authorization header here> Content-Type: application/atom+xml Content-Length: 531 <entry xmlns="http://www.w3.org/2005/Atom"> <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/sites/2008#webattachment" label="webattachment"/> <link rel="http://schemas.google.com/sites/2008#parent" type="application/atom+xml" href="https://sites.google.com/feeds/content/domainName/siteName/FILECABINET_ENTRY_ID"/> <title>GoogleLogo</title> <summary>nice colors</summary> <content type="image/gif" src="http://www.google.com/images/logo.gif"></content> </entry>
POST sẽ tạo một đường liên kết trong tủ hồ sơ của người dùng, trỏ đến hình ảnh tại "http://www.google.com/images/logo.gif".
Cập nhật nội dung
Bạn có thể chỉnh sửa siêu dữ liệu (tiêu đề, pageName, v.v.) và nội dung trang của bất kỳ trang nào bằng một yêu cầu PUT duy nhất đến đường liên kết edit.
Nội dung yêu cầu phải chứa một mục Atom mô tả trang đã cập nhật. Trường hợp ngoại lệ đối với quy tắc này là một mục nhập tệp đính kèm, trong đó mục nhập chỉ có thể dùng để cập nhật siêu dữ liệu của tệp đính kèm.
Để thay đổi nội dung của tệp đính kèm, bạn chỉ cần đưa dữ liệu thô vào nội dung của yêu cầu PUT đối với đường liên kết edit-media của tệp đính kèm. Bạn cũng có thể cập nhật cả siêu dữ liệu và nội dung tệp đính kèm cùng một lúc bằng cách sử dụng yêu cầu nhiều phần MIME.
Để khẳng định rằng nội dung cập nhật của bạn không ghi đè các thay đổi của một ứng dụng khác, hãy thêm giá trị ETag của mục nhập ban đầu. Bạn có thể thực hiện việc này bằng cách cung cấp giá trị ETag trong tiêu đề If-Match HTTP hoặc bằng cách thêm thuộc tính gd:etag của mục ban đầu vào mục đã cập nhật. Để xác định giá trị ETag của mục nhập ban đầu, hãy kiểm tra thuộc tính gd:etag của phần tử <entry>.
Đối với các mục nội dung nghe nhìn, ETag của nội dung nghe nhìn có thể có trong thuộc tính gd:etag của đường liên kết edit-media.
Nếu bạn muốn cập nhật mục nhập bất kể người khác có cập nhật mục nhập đó hay không kể từ khi bạn truy xuất, hãy sử dụng If-Match: * và không thêm ETag. Để biết thêm thông tin về ETag, hãy xem hướng dẫn tham khảo về API Dữ liệu của Google.
Cập nhật siêu dữ liệu hoặc nội dung HTML của một mục
Để cập nhật siêu dữ liệu hoặc nội dung HTML của một mục, hãy gửi một yêu cầu HTTP PUT đến đường liên kết edit của mục đó.
Sau đây là ví dụ về cách cập nhật một mục listpage (được biểu thị bằng mã nhận dạng ENTRY_ID) với những thay đổi sau:
- Tiêu đề được sửa đổi thành "Nội dung cập nhật"
- Nội dung HTML đã cập nhật
- Tiêu đề cột đầu tiên của danh sách được cập nhật thành "Chủ sở hữu"
- Đường dẫn URL của trang được sửa đổi bằng phần tử
<sites:pageName>
PUT /feeds/content/domainName/siteName/ENTRY_ID Host: sites.google.com GData-Version: 1.4 Authorization: <your authorization header here> Content-Length: 816 Content-Type: application/atom+xml <entry xmlns="http://www.w3.org/2005/Atom" xmlns:sites="http://schemas.google.com/sites/2008" xmlns:gs="http://schemas.google.com/spreadsheets/2006" xmlns:gd="http://schemas.google.com/g/2005" gd:etag="W/"CEEBRn0ymA9WxJWEUw.""> <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/sites/2008#listpage" label="listpage"/> <title>Updated Title</title> <content type="xhtml"> <div xmlns="http://www.w3.org/1999/xhtml">Updated Content</div> </content> <gs:worksheet name="listpage"/> <gs:header row="1"/> <gs:data startRow="2"> <gs:column index="A" name="Owner"/> <gs:column index="B" name="Description"/> <gs:column index="C" name="Completed"/> </gs:data> <sites:pageName>newPagePath</sites:pageName> </entry>
Lưu ý: Mục nhập (do máy chủ trả về) sẽ chứa nhiều phần tử hơn ví dụ trên.
Thay thế nội dung của tệp đính kèm
Dưới đây là ví dụ về cách thay thế nội dung của một tệp đính kèm nhưng giữ nguyên siêu dữ liệu của tệp đó. Vì yêu cầu này có chứa nội dung mới, nên đường liên kết edit-media của mục tệp đính kèm sẽ được dùng.
PUT /feeds/media/content/domainName/siteName/ATTACHMENT_ENTRY_ID Host: sites.google.com GData-Version: 1.4 Authorization: <your authorization header here> Content-Length: 70581 Content-Type: application/msword ... doc contents here ...
Cập nhật siêu dữ liệu và nội dung của tệp đính kèm
Dưới đây là ví dụ về cách cập nhật cả siêu dữ liệu và nội dung của tệp đính kèm cùng một lúc. Tên tệp đính kèm sẽ được cập nhật thành "Tiêu đề mới" và nội dung của tệp đính kèm sẽ được thay thế bằng nội dung của một tệp .zip. Vì yêu cầu chứa nội dung tệp mới, nên đường liên kết edit-media của mục nhập tệp đính kèm sẽ được dùng.
Xin lưu ý rằng việc thêm ETag cho siêu dữ liệu cũng cung cấp một If-Match ngầm cho nội dung nghe nhìn, vì mọi nội dung cập nhật cho nội dung nghe nhìn đều khiến ETag của siêu dữ liệu thay đổi.
PUT /feeds/media/content/domainName/siteName/ATTACHMENT_ENTRY_ID Host: sites.google.com GData-Version: 1.4 Authorization: <your authorization header here> Content-Type: multipart/related; boundary="END_OF_PART" --END_OF_PART Content-Type: application/atom+xml <?xml version='1.0' encoding='UTF-8'?> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005" gd:etag="BxAaTxRZAyp7ImBq"> <link rel="http://schemas.google.com/sites/2008#parent" type="application/atom+xml" href="https://sites.google.com/feeds/content/domainName/siteName/ATTACHMENT_ENTRY_ID"/> <title>New Title</title> </entry> --END_OF_PART Content-Type: application/zip ... zip contents here ... --END_OF_PART
Xoá nội dung
Để xoá một mục khỏi Google Sites, trước tiên, hãy truy xuất mục đó, sau đó gửi yêu cầu DELETE đến URL edit của mục. Đây là URL được dùng khi cập nhật siêu dữ liệu hoặc nội dung HTML của một mục.
DELETE /feeds/content/domainName/siteName/ENTRY_ID Host: sites.google.com GData-Version: 1.4 Authorization: <your authorization header here> If-Match: <ETag or * here>
Nếu mục nhập bị xoá thành công, máy chủ sẽ phản hồi bằng mã trạng thái HTTP 200 OK.
Nếu bạn muốn đảm bảo rằng bạn không xoá một mục đã được thay đổi bởi một ứng dụng khác kể từ khi bạn truy xuất mục đó, hãy thêm một tiêu đề HTTP If-Match chứa giá trị ETag của mục ban đầu. Bạn có thể xác định giá trị ETag của mục nhập ban đầu bằng cách kiểm tra thuộc tính gd:etag của phần tử <entry>.
Nếu bạn muốn xoá mục nhập bất kể người khác có cập nhật mục nhập đó kể từ khi bạn truy xuất hay không, hãy sử dụng If-Match: * và không thêm ETag. (Trong trường hợp này, bạn không cần truy xuất mục nhập trước khi xoá.)
Để biết thêm thông tin về ETag, hãy xem hướng dẫn tham khảo về API Dữ liệu của Google.
Tải tệp đính kèm xuống
Sau khi có một mục đính kèm, bạn có thể tải tệp xuống bằng cách gửi một HTTP GET đã xác thực đến đường liên kết <content>src của mục đó. Ví dụ về đường liên kết đến nội dung của một tệp PDF:
<content type="application/pdf" src="http://502377765-a-google-com-s-sites.googlegroups.com/feeds/media/content/domainName/siteName/678942036"/>
Nguồn cấp dữ liệu ACL
Tổng quan về quyền chia sẻ (ACL)
Mỗi mục ACL trong nguồn cấp dữ liệu ACL đại diện cho một vai trò truy cập của một thực thể cụ thể, có thể là người dùng, nhóm người dùng, miền hoặc quyền truy cập mặc định (là một trang web công khai). Các mục nhập sẽ chỉ xuất hiện cho những thực thể có quyền truy cập rõ ràng – một mục nhập sẽ xuất hiện cho mỗi địa chỉ email trong bảng "Người có quyền truy cập" trong màn hình chia sẻ của giao diện người dùng Google Sites. Do đó, quản trị viên miền sẽ không xuất hiện, ngay cả khi họ có quyền truy cập ngầm vào một trang web.
Vai trò
Phần tử vai trò đại diện cho cấp truy cập mà một thực thể có thể có. Có 4 giá trị có thể có của phần tử gAcl:role:
- reader – người xem (tương đương với quyền chỉ có thể đọc).
- người viết – cộng tác viên (tương đương với quyền đọc/ghi).
- chủ sở hữu – thường là quản trị viên trang web (tương đương với quyền đọc/ghi).
Phạm vi
Phần tử phạm vi đại diện cho thực thể có cấp truy cập này. Có 5 loại phần tử gAcl:scope có thể có:
- user – giá trị địa chỉ email, ví dụ: "user@gmail.com".
- group – địa chỉ email của một nhóm trên Google Groups, ví dụ: "group@domain.com".
- domain – tên miền G Suite, ví dụ: "domain.com".
- invite – người dùng đã được mời tham gia trang web nhưng chưa được thêm vào danh sách kiểm soát truy cập (ACL) của trang web. (Không dùng được nếu bạn chỉ định gdata 1.3 trở xuống.)
- default – Chỉ có một phạm vi có thể có thuộc loại "default", không có giá trị (ví dụ:
<gAcl:scope type="default">). Phạm vi cụ thể này kiểm soát quyền truy cập mà bất kỳ người dùng nào có theo mặc định trên một trang web công khai.
Lưu ý: Bạn không thể đặt giá trị gAcl:role cho miền thành quyền truy cập "chủ sở hữu", mà chỉ có thể là người đọc hoặc người viết.
Giới thiệu về phạm vi "mời".
API này trả về phạm vi lời mời khi bạn thêm một hoặc nhiều người dùng vào ACL mà chưa có Tài khoản Google. API này trả về một URL có mã thông báo được nhúng mà bạn phải cung cấp cho người dùng được mời để cho phép họ chấp nhận lời mời.
Phương thức mời này cho phép bạn mời người dùng không phải là người dùng Google mà không cần biết trước địa chỉ email họ muốn sử dụng. Miễn là người dùng nhấp vào URL lời mời có mã thông báo được nhúng, họ có thể đăng ký quyền truy cập bằng bất kỳ địa chỉ email nào họ muốn. Ngoài ra, nhiều người dùng có thể sử dụng URL này để chấp nhận lời mời. Vì vậy, URL này có thể hữu ích nếu bạn mời một người dùng hoặc một nhóm người dùng.
Lưu ý: Phạm vi "mời" chỉ có trong gdata phiên bản 1.4 trở lên. Cách này sẽ không hoạt động nếu bạn chỉ định rõ ràng 1.3 trở xuống.
Truy xuất nguồn cấp dữ liệu ACL
Bạn có thể dùng nguồn cấp dữ liệu ACL để kiểm soát quyền chia sẻ của một trang web và có thể truy cập thông qua URI sau:
https://sites.google.com/feeds/acl/site/domainName/siteName
| Tham số nguồn cấp dữ liệu | Mô tả |
|---|---|
domainName | "site" hoặc miền của tên miền được lưu trữ trên G Suite (ví dụ: example.com). |
siteName | Tên không gian trên web của trang web; có trong URL của trang web (ví dụ: myCoolSite). |
Bạn cần lưu ý rằng mỗi mục trong nguồn cấp dữ liệu trang web đều chứa một đường liên kết đến nguồn cấp dữ liệu này:
<link rel="http://schemas.google.com/acl/2007#accessControlList" type="application/atom+xml"
href="https://sites.google.com/feeds/acl/site/domainName/siteName"/>
Để truy xuất quyền chia sẻ của một trang web, hãy gửi HTTP GET đến URI nguồn cấp dữ liệu ACL:
GET /feeds/acl/site/domainName/siteName HTTP/1.1 Host: sites.google.com GData-Version: 1.4 Authorization: <your authorization header here>
Máy chủ sẽ phản hồi bằng 200 OK và một nguồn cấp dữ liệu gồm các mục ACL:
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/"
xmlns:gAcl="http://schemas.google.com/acl/2007" xmlns:sites="http://schemas.google.com/sites/2008"
xmlns:gs="http://schemas.google.com/spreadsheets/2006" xmlns:dc="http://purl.org/dc/terms"
xmlns:batch="http://schemas.google.com/gdata/batch" xmlns:gd="http://schemas.google.com/g/2005"
xmlns:thr="http://purl.org/syndication/thread/1.0">
<id>https://sites.google.com/feeds/acl/site/domainName/siteName</id>
<updated>2009-12-03T22:01:05.963Z</updated>
<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/acl/2007#accessRule"/>
<title>Acl</title>
<link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml"
href="https://sites.google.com/feeds/acl/site/domainName/siteName"/>
<link rel="http://schemas.google.com/g/2005#post" type="application/atom+xml"
href="https://sites.google.com/feeds/acl/site/domainName/siteName"/>
<link rel="self" type="application/atom+xml"
href="https://sites.google.com/feeds/acl/site/domainName/siteName"/>
<generator version="1" uri="http://sites.google.com">Google Sites</generator>
<openSearch:startIndex>1</openSearch:startIndex>
<entry>
<id>https://sites.google.com/feeds/acl/site/domainName/siteName/user%3AuserA%40gmail.com</id>
<updated>2009-12-03T22:01:05.963Z</updated>
<app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-03T22:01:05.963Z</app:edited>
<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/acl/2007#accessRule"/>
<link rel="self" type="application/atom+xml"
href="https://sites.google.com/feeds/acl/site/domainName/siteName/user%3AuserA%40google.com"/>
<link rel="edit" type="application/atom+xml"
href="https://sites.google.com/feeds/acl/site/domainName/siteName/user%3AuserA%40google.com"/>
<gAcl:scope type="user" value="userA@google.com"/>
<gAcl:role value="owner"/>
</entry>
<entry>
<id>https://sites.google.com/feeds/acl/site/domainName/siteName/user%3AuserB%40gmail.com</id>
<updated>2009-12-03T22:01:05.963Z</updated>
<app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-03T22:01:05.963Z</app:edited>
<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/acl/2007#accessRule"/>
<link rel="self" type="application/atom+xml"
href="https://sites.google.com/feeds/acl/site/domainName/siteName/user%3AuserB%40gmail.com"/>
<link rel="edit" type="application/atom+xml"
href="https://sites.google.com/feeds/acl/site/domainName/siteName/user%3AuserB%40gmail.com"/>
<gAcl:scope type="user" value="userB@gmail.com"/>
<gAcl:role value="writer"/>
</entry>
<entry>
<id>https://sites.google.com/feeds/acl/site/domainName/siteName/user%3AuserC%40gmail.com</id>
<updated>2009-12-03T22:01:05.963Z</updated>
<app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-03T22:01:05.963Z</app:edited>
<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/acl/2007#accessRule"/>
<link rel="self" type="application/atom+xml"
href="https://sites.google.com/feeds/acl/site/domainName/siteName/user%3AuserC%40gmail.com"/>
<link rel="edit" type="application/atom+xml"
href="https://sites.google.com/feeds/acl/site/domainName/siteName/user%3AuserC%40gmail.com"/>
<gAcl:scope type="user" value="userC@gmail.com"/>
<gAcl:role value="reader"/>
</entry>
...
</feed>
Chia sẻ trang web
Nguồn cấp dữ liệu ACL chấp nhận các yêu cầu GET, POST và PUT. Để chèn một vai trò mới vào nguồn cấp dữ liệu ACL, bạn chỉ cần đưa ra yêu cầu POST đối với nguồn cấp dữ liệu ACL của trang web.
Lưu ý: Một số ACL chia sẻ chỉ có thể thực hiện được nếu miền được định cấu hình để cho phép các quyền đó (ví dụ: nếu bạn bật tính năng chia sẻ bên ngoài miền cho các miền G Suite, v.v.).
Ví dụ này thêm một cộng tác viên mới (nhà văn) vào trang web:
POST /feeds/acl/site/domainName/siteName HTTP/1.1 Host: sites.google.com GData-Version: 1.4 Authorization: <your authorization header here> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:gAcl='http://schemas.google.com/acl/2007'> <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/acl/2007#accessRule'/> <gAcl:role value='writer'/> <gAcl:scope type='user' value='new_writer@example.com'/> </entry>
201 Created và mục nhập mới sẽ được trả về khi chèn thành công:
<entry> <id>https://sites.google.com/feeds/acl/site/domainName/siteName/user%3Anew_writer%40example.com</id> <updated>2009-12-03T22:01:05.963Z</updated> <app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-03T22:01:05.963Z</app:edited> <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/acl/2007#accessRule"/> <link rel="self" type="application/atom+xml" href="https://sites.google.com/feeds/acl/site/domainName/siteName/user%3Anew_writer%40example.com"/> <link rel="edit" type="application/atom+xml" href="https://sites.google.com/feeds/acl/site/domainName/siteName/user%3Anew_writer%40example.com"/> <gAcl:role value='writer'/> <gAcl:scope type='user' value='new_writer@example.com'/> </entry>
Mời người dùng thông qua phạm vi "invite"
Nếu bạn thêm người dùng không có Tài khoản Google, API sẽ trả về một URL mà bạn phải cung cấp cho người dùng mà bạn muốn mời. Sau khi nhấp vào URL, họ sẽ có thể truy cập vào trang web bằng cách đăng nhập bằng một tài khoản hiện có hoặc tạo một tài khoản mới.
Lời mời thành công sẽ trả về một 201 Created và một mục mới có chứa URL mà bạn phải chuyển cho người dùng:
<entry> <id>https://sites.google.com/feeds/acl/site/domainName/siteName/user%3Anew_invite%40example.com</id> <updated>2009-12-03T22:01:05.963Z</updated> <app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-03T22:01:05.963Z</app:edited> <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/acl/2007#accessRule"/> <link rel="http://schemas.google.com/sites/2008#invite" type="text/html"href="domainName/siteName?invite=inviteToken"/> <link rel="self" type="application/atom+xml" href="https://sites.google.com/feeds/acl/site/domainName/siteName/user%3Anew_invite%40example.com"/> <link rel="edit" type="application/atom+xml" href="https://sites.google.com/feeds/acl/site/domainName/siteName/user%3Anew_invite%40example.com"/> <gAcl:role value='writer'/> <gAcl:scope type='invite' value='new_invite%40example.com'/> </entry>
Chia sẻ ở cấp nhóm và miền
Tương tự như chia sẻ trang web với một người dùng, bạn có thể chia sẻ trang web với một nhóm trên Google hoặc miền G Suite. Các giá trị scope cần thiết được liệt kê bên dưới.
Chia sẻ với địa chỉ email của nhóm:
<gAcl:scope type="group" value="group@example.com"/>
Chia sẻ với toàn bộ miền:
<gAcl:scope type="domain" value="example.com"/>
Chế độ chia sẻ ở cấp miền chỉ được hỗ trợ cho các miền G Suite và chỉ dành cho miền lưu trữ trang web. Ví dụ: http://sites.google.com/a/domain1.com/siteA chỉ có thể chia sẻ toàn bộ Trang web với domain1.com, chứ không thể chia sẻ với domain2.com. Những Trang web không được lưu trữ trên miền G Suite (ví dụ: http://sites.google.com/site/siteB) không thể mời miền.
Sửa đổi quyền chia sẻ
Để cập nhật một mục ACL, hãy sửa đổi mục đó nếu cần và đưa ra yêu cầu HTTP PUT đến đường liên kết edit của mục. Đây chỉ đơn giản là một phần tử <link>, có thuộc tính "rel" được đặt thành "edit". Đối với ví dụ trước, đường liên kết đó là:
<link rel='edit' type='application/atom+xml'
href='https://sites.google.com/feeds/acl/site/domainName/siteName/user%3Anew_writer%40example.com'/>Đoạn mã dưới đây thay đổi vai trò của new_writer@gmail.com thành "người đọc":
PUT /feeds/acl/site/domainName/siteName/user%3Anew_writer%40example.com HTTP/1.1 Host: sites.google.com GData-Version: 1.4 Authorization: <your authorization header here> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:gAcl='http://schemas.google.com/acl/2007'> <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/acl/2007#accessRule'/> <gAcl:role value='reader'/> <gAcl:scope type='user' value='new_writer@gmail.com'/> </entry>
Xoá quyền chia sẻ
Để xoá quyền của người dùng này, hãy gửi yêu cầu DELETE đến cùng một đường liên kết edit đã dùng cho yêu cầu PUT:
DELETE /feeds/acl/site/domainName/siteName/user%3Anew_writer%40example.com HTTP/1.1 Host: sites.google.com GData-Version: 1.4 Authorization: <your authorization header here>
Máy chủ sẽ phản hồi bằng 200 OK.
Chủ đề đặc biệt
Lấy lại nguồn cấp dữ liệu hoặc mục
Nếu muốn truy xuất một nguồn cấp dữ liệu hoặc mục mà bạn đã truy xuất trước đó, bạn có thể cải thiện hiệu quả bằng cách yêu cầu máy chủ chỉ gửi danh sách hoặc mục nếu danh sách hoặc mục đó đã thay đổi kể từ lần gần nhất bạn truy xuất.
Để thực hiện loại truy xuất có điều kiện này, hãy gửi một yêu cầu HTTP GET có chứa tiêu đề HTTP If-None-Match. Trong tiêu đề, hãy chỉ định ETag của danh sách hoặc mục. Bạn có thể tìm thấy ETag này trong thuộc tính gd:etag của phần tử <feed> hoặc phần tử <entry>.
Ví dụ sử dụng nguồn cấp dữ liệu trang web:
GET /feeds/site/domainName/myOtherTestSite/ GData-Version: 1.4 If-None-Match: W/"Ck8GQXk7fil7ImA9WxNSFk0."
Khi nhận được yêu cầu này, máy chủ sẽ kiểm tra xem mục mà bạn yêu cầu có cùng ETag với ETag mà bạn đã chỉ định hay không. Nếu ETag khớp, thì tức là mục chưa thay đổi và máy chủ sẽ trả về mã trạng thái HTTP 304 Not Modified hoặc mã trạng thái HTTP 412 Precodition Failed. Cả hai mã trạng thái đó đều cho biết rằng mặt hàng bạn đã truy xuất là mới nhất.
Nếu ETag không khớp, thì tức là mục đã được sửa đổi kể từ lần gần đây nhất bạn yêu cầu và máy chủ sẽ trả về mục đó.
Để biết thêm thông tin về ETag, hãy xem hướng dẫn tham khảo về API Dữ liệu của Google.
Xử lý hàng loạt
Yêu cầu hàng loạt cho phép ứng dụng khách của bạn thực thi nhiều thao tác trong một yêu cầu thay vì gửi từng thao tác riêng lẻ.
Máy chủ sẽ thực hiện nhiều thay đổi được yêu cầu nhất có thể và trả về thông tin trạng thái mà bạn có thể dùng để đánh giá mức độ thành công hoặc thất bại của từng thao tác. Để biết thêm thông tin chi tiết về quy trình xử lý hàng loạt trong Google Data API, hãy xem Quy trình xử lý hàng loạt bằng Google Data API
Mọi thao tác trong nguồn cấp dữ liệu hàng loạt đều có một phần tử <id>, ngoại trừ thao tác chèn.
Phần tử này giống với URL yêu cầu mà bạn thường dùng khi cập nhật, xoá hoặc truy vấn nguồn cấp nội dung.
Ví dụ: nếu bạn đang cập nhật một nội dung chỉnh sửa, hãy đặt <id> thành đường liên kết edit cho mục nhập có liên quan.
Thuộc tính này dùng để xác định mục nhập đích. Các mục mới không có phần tử <id> vì chúng chưa được tạo. Thay vào đó, bạn có thể xác định một giá trị chuỗi trong <batch:id>. Giá trị này sẽ được trả về trong phản hồi của máy chủ và dùng để tra cứu mục nhập tương ứng.
Để thực hiện yêu cầu hàng loạt, hãy tạo một nguồn cấp dữ liệu hàng loạt và gửi một yêu cầu HTTP POST đến đường liên kết hàng loạt của nguồn cấp dữ liệu:
<link rel="http://schemas.google.com/g/2005#batch" type="application/atom+xml"
href="https://sites.google.com/feeds/content/site/siteName/batch"/>
Ví dụ dưới đây cho thấy cách truy vấn, chèn, cập nhật và xoá một mục trên trang web:
POST /feeds/content/site/siteName/batch HTTP/1.1 Host: sites.google.com Accept: */* If-Match: * GData-Version: 1.4 Authorization: <your authorization header here> <feed xmlns="http://www.w3.org/2005/Atom" xmlns:sites="http://schemas.google.com/sites/2008" xmlns:gd="http://schemas.google.com/g/2005" xmlns:batch='http://schemas.google.com/gdata/batch'> <entry> <id>https://sites.google.com/feeds/content/site/siteName/ENTRY_ID1</id> <batch:operation type="query"/> </entry> <entry> <batch:id>1</batch:id> <batch:operation type='insert'/> <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/sites/2008#webpage" label="webpage"/> <title>New Webpage1</title> <content type="xhtml"> <div xmlns="http://www.w3.org/1999/xhtml">HTML body goes here</div> </content> </entry> <entry gd:etag=""YDgpeyI.""> <id>https://sites.google.com/feeds/content/site/siteName/ENTRY_ID2</id> <batch:operation type='update'/> <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/sites/2008#webpage" label="webpage"/> <title>Updated Title for Webpage2</title> ... <batch:operaation type="update"/> </entry> <entry gd:etag=""YassseyI.""> <id>https://sites.google.com/feeds/content/site/siteName/ENTRY_ID3</id> <batch:operation type='delete'/> </entry> </feed>
Nguồn cấp dữ liệu được trả về sẽ chứa một mục kết quả cho mỗi thao tác:
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/"
xmlns:sites="http://schemas.google.com/sites/2008" xmlns:gs="http://schemas.google.com/spreadsheets/2006"
xmlns:dc="http://purl.org/dc/terms" xmlns:batch="http://schemas.google.com/gdata/batch"
xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0">
<id>https://sites.google.com/feeds/content/site/siteName/ENTRY_ID1</id>
<updated>2009-11-10T22:44:08.369Z</updated>
<title>Batch Feed</title>
<entry gd:etag=""YDgpsdfeyI."">
<id>https://sites.google.com/feeds/content/site/siteName/ENTRY_ID1</id>
<published>2009-08-31T04:42:45.251Z</published>
<updated>2009-10-25T22:46:13.729Z</updated>
<app:edited xmlns:app="http://www.w3.org/2007/app">2009-10-25T22:46:13.671Z</app:edited>
<category scheme="http://schemas.google.com/g/2005#kind"
term="http://schemas.google.com/sites/2008#webpage" label="webpage"/>
<title>Page Title</title>
...
<batch:status code="200" reason="Success"/>
<batch:operation type="query"/>
</entry>
<entry gd:etag=""YDsseyI."">
<id>https://sites.google.com/feeds/content/site/siteName/ENTRY_ID4</id>
<published>2009-11-10T22:44:08.531Z</published>
<updated>2009-11-10T22:44:08.560Z</updated>
<app:edited xmlns:app="http://www.w3.org/2007/app">2009-11-10T22:44:08.531Z</app:edited>
<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/sites/2008#webpage" label="webpage"/>
<title>New Webpage1</title>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<table cellspacing="0" class="sites-layout-name-one-column sites-layout-hbox">
<tbody>
<tr>
<td class="sites-layout-tile sites-tile-name-content-1">
<div>HTML body goes here</div>
</td>
</tr>
</tbody>
</table>
</div>
</content>
...
<batch:id>1</batch:id>
<batch:status code="201" reason="Created"/>
<batch:operation type="insert"/>
</entry>
<entry gd:etag=""YDkpeyI."">
<id>https://sites.google.com/feeds/content/site/siteName/ENTRY_ID2</id>
<updated>2009-11-10T22:44:09.296Z</updated>
<title>Updated Title for Webpage2</title>
...
<sites:pageName>updated-title-for-webpage2</sites:pageName>
<sites:revision>5</sites:revision>
<batch:status code="200" reason="Success"/>
<batch:operation type="update"/>
</entry>
<entry>
<id>https://sites.google.com/feeds/content/site/siteName/ENTRY_ID3</id>
<title>Deleted</title>
<content>Deleted</content>
<batch:status code="200" reason="Success"/>
<batch:operation type="delete"/>
</entry>
</feed>