API Google Sites cũ 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 Trang web Google. Ngoài ra, ứng dụng của bạn có thể yêu cầu một danh sách hoạt động gần đây, tìm nạp nhật ký sửa đổi, cũng như tải lên/tải xuống các tệp đính kèm và tệp.
Đối tượng người xem
Tài liệu này giả định rằng bạn hiểu các ý 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. Trang này cung cấp một loạt ví dụ về các hoạt động tương tác với API dữ liệu cơ bản bằng cách sử dụng tệp XML/HTTP thô, kèm theo nội dung 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 cách sử dụng thư viện ứng dụng của chúng tôi bằng cách đọc các ví dụ về 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 ứng dụng của bạn yêu cầu dữ liệu người dùng không công khai, ứng dụng đó phải bao gồm mã cấp phép. 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
Yêu cầu API dữ liệu trang web của Google đối với dữ liệu người dùng không công khai phải được người dùng đã xác thực cấp phép.
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ư ID ứng dụng khách và khoá bí mật của ứng dụng.
- 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 của OAuth 2.0 cho API dữ liệu Google Sites:
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ư ID ứng dụng khách và khoá bí mật của ứng dụng).
Chỉ định một phiên bản
Mỗi yêu cầu mà bạn gửi tới API dữ liệu trang web của Google phải chỉ định phiên bản 1.4. Để chỉ định số phiên bản, hãy sử 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. Nhưng tiêu đề HTTP sẽ được ưu tiên 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, không sử dụng tham số truy vấn v=1.4
khi bạn đang sử dụng thư viện ứng dụng.
Nguồn cấp dữ liệu trang web
Bạn có thể sử dụng nguồn cấp dữ liệu trang web để liệt kê các trang web Google Sites mà người dùng sở hữu hoặc có quyền xem cũng như sửa đổi tiêu đề của trang web hiện có. Đối với các miền G Suite, bạn cũng có thể sử dụng miền này để tạo hoặc sao chép toàn bộ trang web.
Trang web danh sách
Để liệt kê các trang web mà người dùng có quyền truy cập, hãy gửi yêu cầu GET
đã xác thực đến URL sau:
https://sites.google.com/feeds/site/domainName
Thông số nguồn cấp dữ liệu | Mô tả |
---|---|
domainName | 'site ' hoặc miền của miền G Suite được lưu trữ (ví dụ: example.com ). |
Phản hồi sẽ chứa nguồn cấp dữ liệu có một 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ỉ dành cho miền G Suite.
Bạn có thể cấp phép trang web mới bằng cách tạo 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 nêu trên sẽ tạo một trang web tạo bằng Google Sites mới có chủ đề "Phương tiện chặ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 bạn tạo trang web thành công, máy chủ sẽ phản hồi bằng 201 Created
.
Mục phản hồi sẽ chứa các phần tử mà máy chủ thêm vào, chẳng hạn như một đường liên kết đến
trang web, một đườ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.
<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ỉ dành cho 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ư tạo trang web mới. Tuy nhiên, trong mục nhập Atom của yêu cầu POST
, hãy thêm <link>
có rel='source'
trỏ đến nguồn cấp dữ liệu trang web của trang web để sao chép. Bất kỳ trang web nào đã được sao chép sẽ có liên kết này. Dưới đây là ví dụ về cách sao chép 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/.
Điểm quan trọng:
- Bạn chỉ có thể sao chép 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. Trang web là mẫu nếu chế độ cài đặt "Xuất bản trang web này làm mẫu" được chọn trong trang cài đặt của Google Sites.
- Bạn có thể sao chép trang web từ một miền khác, đang chờ xử lý với tư cách 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 tóm tắt của một trang web, hãy gửi đường liên kết HTTP PUT
đến đường liên kết edit
của mục nhập trang web.
Ví dụ: ví dụ sau 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ỉ dành cho miền G Suite.
G Suite cho trang web trong miền của bạn có chứa siêu dữ liệu danh mục rất 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 đường liên kết HTTP PUT
đến mục nhập edit
trong mục nhập trang web bao gồm thẻ category
. Hãy xem dòng 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 của 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 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 của nhóm" và "Nhóm pháp lý"
Liên kết địa chỉ web
Việc ánh xạ đị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 tạo bằng Google Sites. Ví dụ: bạn có thể sử 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, bạn có thể sửa đổi sơ đồ liên kết địa chỉ web của trang web theo cách thủ công. Hãy xem bài viết trong trung tâm trợ giúp của chúng tôi để biết thêm thông tin.
Tìm nạp dữ liệu ánh xạ địa chỉ web của trang web
Để trả về dữ liệu ánh xạ địa chỉ web cho một trang web, hãy tìm nạp mục nhập trang web/nguồn cấp dữ liệu 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ục ánh xạ hiện có sẽ hiển thị dưới dạng link
có rel='webAddressMapping'. Ví dụ: trong ví dụ trên, có ba webAddressMapping
trỏ đến trang web http://sites.google.com/site/myOtherTestSite
.
Sửa đổi mối liên kết địa chỉ web
Lưu ý: Tất cả thao tác GET/POST/PUT phải chỉ định tham số with-mappings=true
khi làm việc với các liên kết địa chỉ web. Nếu không có tham số này, webAddressMapping
sẽ không được trả về trong các mục nhập trang web (GET) hoặc được xem xét khi liên kết cập nhật/xoá (PUT) khỏi một mục.
Để thêm, cập nhật hoặc xoá mối liên kết, bạn chỉ cần chỉ định, thay đổi hoặc xoá đường liên kết đó khi tạo trang web mới hoặc
cập nhật siêu dữ liệu của trang web. Tham số with-mappings=true
phải được đưa vào URI nguồn cấp dữ liệu trang web.
Lưu ý: để cập nhật các mục ánh xạ địa chỉ, bạ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 cập nhật bản đồ ánh xạ http://www.mysitemapping.com
thành http://www.my-new-sitemapping.com
,
và xoá http://www.mysitemapping2.com
bằng cách để đường liên kết ra 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>
Lưu ý rằng bạn cũng có thể chỉ định ánh xạ địa chỉ web tại thời điểm tạo/sao chép 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 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 chứa thông tin về một thay đổi đã được thực hiện trên Trang web.
Để truy vấn nguồn cấp dữ liệu hoạt động, hãy gửi một HTTP GET
đến URL của nguồn cấp dữ liệu hoạt động:
https://sites.google.com/feeds/activity/domainName/siteName
Thông số nguồn cấp dữ liệu | Mô tả |
---|---|
domainName | 'site ' hoặc miền của miền G Suite được lưu trữ (ví dụ: example.com ). |
siteName | Tên trang web của trang web của bạn; 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 ý: Để truy cập vào nguồn cấp dữ liệu này, bạn phải là cộng tác viên hoặc chủ sở hữu của Trang web.
Ứng dụng khách của bạn phải gửi đúng tiêu đề Authorization
và tham chiếu mã thông báo thu được trong phần Cấp phép yêu cầu.
Nguồn cấp dữ liệu sửa đổi
Để tìm nạp nhật ký sửa đổi cho bất kỳ mục nhập nội dung nào, hãy gửi HTTP GET
đến liên kết sửa đổi của mục nhập:
https://sites.google.com/feeds/revision/domainName/siteName/CONTENT_ENTRY_ID
Thông số nguồn cấp dữ liệu | Mô tả |
---|---|
domainName | 'site ' hoặc miền của miền G Suite được lưu trữ (ví dụ: example.com ). |
siteName | Tên trang web của trang web của bạn; có trong URL của trang web (ví dụ: myCoolSite ). |
Để tìm đường liên kết sửa đổi cho một trang/nhận xét/tệp đính kèm/danh sách nhất định, trước tiên hãy truy xuất mục nhập từ nguồn cấp nội dung bằng cách sử dụng CONTENT_Entry_ID. Mục nhập được truy xuất sẽ chứa <atom:link>
cho nguồn cấp dữ liệu 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 ý: Để truy cập vào nguồn cấp dữ liệu này, bạn phải là cộng tác viên hoặc chủ sở hữu của Trang web.
Ứng dụng khách của bạn phải gửi đúng tiêu đề Authorization
và tham chiếu mã thông báo thu được trong phần Cấp phép yêu cầu.
Nguồn cấp 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 trang web. Gửi yêu cầu GET
đã xác thực đến URL sau:
https://sites.google.com/feeds/content/domainName/siteName
Thông số nguồn cấp dữ liệu | Mô tả |
---|---|
domainName | 'site ' hoặc miền của miền G Suite được lưu trữ (ví dụ: example.com ). |
siteName | Tên trang web của trang web của bạn; 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 nhập nội dung khác nhau, 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 nhập. Xem hướng dẫn tham khảo để biết danh sách các giá trị kind
hỗ trợ.
Lưu ý: Nguồn cấp dữ liệu này có thể cần hoặc không cần xác thực, tuỳ thuộc vào quyền chia sẻ của Trang web.
Nếu Trang web không công khai, ứng dụng của bạn phải gửi đúng tiêu đề Authorization
(như trong ví dụ ở trên) và tham chiếu mã thông báo thu được trong phần Cấp phép 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. Để mở trang thông qua toàn bộ nguồn cấp nội dung, hãy truy cập đườ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"/>
Để tham khảo phần giải thích về các phần tử phổ biến 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ử chứa một phương tiện cụ thể cho API Sites cũ được mô tả dưới đây. Một số loại mục nhất định sẽ có các thuộc tính bổ sung (không được liệt kê bên dưới), trong khi các mục khác sẽ không có. Ví dụ: mục listitem
có thể có phần tử <gs:field>
, còn mục webpage
thì không.
Phần tử | Mô tả |
---|---|
<content ...> | Văn bản bên trong là phần nội dung HTML của trang. Đối với một số mục nhập (ví dụ: tệp đính kèm), phần tử này sẽ chứa thuộc tính src trỏ đến tệp. |
<link rel="alternate" ...> | Liên kết với 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ỏ vào 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 nhập. |
<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 biểu thị mục nhập là một mẫu. |
<gd:feedLink> | Thuộc tính href trỏ đến thành phần con của phần tử mẹ. |
<sites:pageName> | Tên trang web của trang; tương ứng với tên trong URL của trang. |
<sites:revision> | Số bản sửa đổi 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 nguồn cấp nội dung bằng cách sử dụng một số tham số truy vấn API dữ liệu chuẩn của Google và những tham số cụ thể cho API Sites cũ. Để biết thêm thông tin chi tiết và danh sách đầy đủ các tham số được hỗ trợ, hãy xem Hướng dẫn tham khảo.
Truy xuất loại mục nhập cụ thể
Để chỉ tìm nạp một loại mục cụ thể, hãy sử dụng thông số kind
. Ví dụ này chỉ trả về mục nhập 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ề 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 truy vấn /-/category
Dữ liệu của Google 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ề template
trang:
GET /feeds/content/domainName/siteName/-/template
Để trả về tất cả các loại mục nhập và bao gồm template
trang, hãy sử dụng:
GET /feeds/content/domainName/siteName/-/template|-template
Truy xuấ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ể sử 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 nhập trong trang gốc
Nếu biết mã mục nhập của trang, bạn có thể sử dụng tham số parent
để tìm nạp tất cả các mục con (nếu có):
GET /feeds/content/domainName/siteName?parent=CONTENT_ENTRY_ID
Bao gồm bản nháp hoặc mục nhập đã bị xóa
Để thêm các mục nháp hoặc mục đã xóa, hãy sử dụng tham số include-drafts
hoặc include-deleted
tương ứng.
Ví dụ này bao gồm các mục nhập 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 trang web, hãy sử dụng tham số q
để thực hiện tìm kiếm toàn bộ văn bả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ổ chức tệp, trang thông báo, v.v.) bằng cách gửi 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 sẽ tạo một webpage
mới ở cấp cao nhất của trang web, bao gồm một số XHTML cho phần nội dung trang và đặt tiêu đề cho "New WebPage Title":
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à bản sao của mục nhập.
Tạo mục/trang trong đường dẫn URL tuỳ chỉnh
Theo mặc định, ví dụ trước sẽ được tạo theo 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à "File Storage" (Bộ nhớ tệp), nhưng lại tạo trang dưới 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 để đặ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 để trống nếu không có pageName. Chuẩn hoá là cắt bớ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 các trang con (trang con) trong một trang gốc, hãy thêm <link rel="http://schemas.google.com/sites/2008#parent">
vào mục nhập Atom mới. Đặt thuộc tính href
của đường liên kết thành đường liên kết chính của mục nhập mẹ.
Ví dụ này tạo một announcement
mới có tiêu đề là "thông báo" trên một trang thông báo chính có mã mục nhập PARENT_ENTRY_ID
. Nội dung XHTML cho nội dung trang cũng được bao gồm:
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 như quá trình tạo mục/trang mới và
tạo trang con.Điểm khác biệt là thêm category
có cụm từ và nhãn được đặt thành 'http://schemas.google.com/g/2005#template'
và 'template' 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ột mẫu
Tương tự như việc tạo mẫu trang, bạn có thể tạo trang mới từ một mẫu bằng cách bao gồm <link>
có rel='http://schemas.google.com/sites/2008#template' trỏ đến đường liên kết 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 trang tổ chức tệp.
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 <category>
, nhưng bạn vẫn phải nhập một mẫu trong 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 cho phép bạn tải tệp đính kèm lên các trang tổ chức tệp và các trang gốc.
Để tải tệp đính kèm lên cha 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
Phần thân POST
phải là một yêu cầu nhiều phần 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
đường liên kết tự nhập của mục nhập mẹ để chỉ định vị trí tạo tệp đính kèm.
Xem Tạo trang con để biết thêm thông tin.
Đang tải tệp đính kèm lên
Dưới đây là ví dụ về cách tải tệp PDF lên tủ tệp có mã 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 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 tải lên thành công, máy chủ sẽ phản hồi bằng một 201 Created
và một bản sao của mục nhập tệp đính kèm mới tạo.
Tải tệp đính kèm lên thư mục
Để tải tệp đính kèm lên 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à các loại tệp đính kèm đặc biệt. Về cơ bản, đó là các đường liên kết đến các tệp khác trên web mà bạn có thể thêm vào trang thông tin trên ngăn xếp tệp của mình. Tính năng này tương tự như phương pháp tải lên "Thêm tệp bằng URL" trong giao diện người dùng Google Sites.
Lưu ý: Bạn chỉ có thể tạo tệp đính kèm trên web trong một ngăn chứa tệp. Bạn không thể tải các trang này lên các loại trang khác.
Ví dụ này sẽ tạo một webattachment
dưới dạng ngăn chứa tệp mà mã nhận dạng FILECABINET_ENTRY_ID
tham chiếu.
Tiêu đề và nội dung mô tả (không bắt buộc) được đặt thành "GoogleBiểu tượng" và "màu sắc đẹp" tương ứng.
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
tạo một đường liên kết trong trang tổ chức tệp 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 đề, tên trang, 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. Ngoại lệ của 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ể được 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ô làm nội dung của yêu cầu PUT
vào đườ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.
Để xác nhận rằng nội dung cập nhật của bạn không ghi đè các thay đổi của một khách hàng khác, hãy bao gồ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 đề HTTP If-Match
hoặc bằng cách thêm thuộc tính gd:etag
của mục gốc vào mục nhập đã 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 đa phương tiện, ETag của nội dung nghe nhìn có thể có sẵn 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 đó kể từ khi bạn truy xuất hay không, 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 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 ID 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 phần tử
<sites:pageName>
sửa đổi
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="Decription"/> <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 thành phần hơn so với 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 tệp đính kèm nhưng không thay đổi siêu dữ liệu của tệp đính kèm. Vì yêu cầu này chứa nội dung mới, nên đường liên kết đến edit-media
của mục đính kèm sẽ được sử 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 đính kèm + nội dung
Dưới đây là ví dụ về cách cập nhật cùng lúc siêu dữ liệu của tệp đính kèm và nội dung của tệp đính kèm. 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 sẽ được thay thế bằng nội dung của tệp .zip. Vì yêu cầu này chứa nội dung tệp mới, nên đường liên kết edit-media
của mục đính kèm sẽ được sử dụng.
Lưu ý rằng việc bao gồm ETag cho siêu dữ liệu cũng cung cấp một If-Match
ngầm định cho nội dung đa phương tiện, vì mọi cập nhật đối với nội dung đa phương tiệ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
Đang xoá nội dung
Để xoá một mục khỏi một trang web tạo bằng 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 cũng 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 bạn đã xoá thành công mục nhập, máy chủ sẽ phản hồi bằng HTTP 200 OK
.
Nếu bạn muốn đảm bảo rằng bạn không xoá một mục đã được một ứng dụng khác thay đổi kể từ khi bạn truy xuất mục đó, hãy thêm tiêu đề HTTP If-Match
chứa giá trị ETag của mục nhập ban đầu. Bạn có thể xác định giá trị ETag của mục gốc 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 đó 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 trước khi xoá.)
Để biết thêm thông tin về ETag, hãy xem Hướng dẫn tham khảo Google Data API.
Đang tải xuống tệp đính kèm
Sau khi có nội dung đí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>
của mục này. Ví dụ về đường liên kết đến nội dung của 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 nhập 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à một người dùng, một nhóm người dùng, một miền hoặc quyền truy cập mặc định (là một trang web công khai). Các mục sẽ chỉ hiển thị cho các mục có quyền truy cập rõ ràng – một mục sẽ được hiển thị cho từng địa chỉ email trong bảng điều khiển "Người có quyền truy cập" trên 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 được hiển thị, mặc dù họ có quyền truy cập ngầm định 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
:
- read – một người xem (tương đương với quyền chỉ có thể đọc).
- author — mộ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 truy cập đọc/ghi).
Kính ngắm
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
:
- user — một giá trị địa chỉ email, ví dụ: "user@gmail.com".
- group - địa chỉ email của Nhóm Google, ví dụ: "group@domain.com".
- mien — tên miền G Suite, ví dụ: "domain.com".
- mời — người dùng đã được mời vào trang web, nhưng chưa được thêm vào ACL cho trang web đó. (Không khả dụng nếu gdata 1.3 hoặc phiên bản thấp hơn được chỉ định.)
- 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 của mọi người dùng theo mặc định trên trang web công khai.
Lưu ý: Miền không được có giá trị gAcl:role
được đặt thành quyền truy cập "chủ sở hữu", chỉ có thể là người đọc hoặc người viết.
Giới thiệu về phạm vi "lời mời".
API 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 những người chưa có tài khoản Google. API sẽ 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 pháp mời này cho phép bạn mời người dùng không phải Google 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ý để 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, do đó, điều 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 "lời mời" chỉ có trong gdata phiên bản 1.4 trở lên. Bạn sẽ không thể sử dụng cách này nếu đang chỉ định rõ ràng phiên bản 1.3 trở xuống.
Đang truy xuất nguồn cấp dữ liệu ACL
Bạn có thể sử dụng nguồn cấp dữ liệu ACL để kiểm soát quyền chia sẻ của trang web và có thể truy cập qua URI sau:
https://sites.google.com/feeds/acl/site/domainName/siteName
Thông số nguồn cấp dữ liệu | Mô tả |
---|---|
domainName | 'site ' hoặc miền của miền G Suite được lưu trữ (ví dụ: example.com ). |
siteName | Tên trang web của trang web của bạn; có trong URL của trang web (ví dụ: myCoolSite ). |
Xin lưu ý rằng mỗi mục nhập trong nguồn cấp dữ liệu trang web 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 trang web, hãy gửi và 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à nguồn cấp dữ liệu của các mục nhập 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
cho nguồn cấp dữ liệu ACL của trang web.
Lưu ý: Bạn chỉ có thể sử dụng một số ACL chia sẻ nếu miền được định cấu hình để cho phép các quyền đó (ví dụ: nếu tính năng chia sẻ bên ngoài miền của miền G Suite được bật, v.v.).
Ví dụ này thêm một cộng tác viên (người viết) mới 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 đượ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 qua phạm vi "mời"
Nếu bạn thêm người dùng không có Tài khoản Google, API sẽ trả về URL mà bạn phải cung cấp cho những người dùng mà bạn muốn mời. Sau khi nhấp vào URL đó, họ có thể truy cập vào trang web bằng cách đăng nhập bằng 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ề 201 Created
và mục nhập 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ư việc chia sẻ một trang web với một người dùng, bạn có thể chia sẻ một trang web trên một nhóm Google hoặc miền G Suite. Các giá trị scope
cần thiết được liệt kê dưới đây.
Chia sẻ với một địa chỉ email 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"/>
Tính năng chia sẻ ở cấp miền chỉ được hỗ trợ cho miền G Suite và chỉ được hỗ trợ 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 miền1.com, không chia sẻ miền2.com. Các 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ục nhập ACL, hãy sửa đổi mục nhập nếu cần và đưa ra yêu cầu HTTP PUT
cho liên kết edit
của mục nhập, đơn giản là phần tử <link>
có thuộc tính 'rel' được đặt thành 'edit'. Trong 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>
Đang xóa quyền chia sẻ
Để xoá quyền cho người dùng này, hãy đưa ra yêu cầu DELETE
cho cùng một đường liên kết edit
đã được 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
Truy xuất lại nguồn cấp dữ liệu hoặc mục nhập
Nếu muốn truy xuất một nguồn cấp dữ liệu hoặc mục nhập 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 nhập nếu nó đã thay đổi kể từ lần gần đây nhất bạn truy xuất nguồn cấp dữ liệu đó.
Để 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
bao gồm tiêu đề HTTP If-None-Match
. Trong tiêu đề, hãy chỉ định ETag của danh sách hoặc mục nhập. Bạn có thể tìm thấy giá trị này trong thuộc tính gd:etag
của phần tử <feed>
hoặc <entry>
.
Ví dụ về cách 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ó giống ETag với ETag mà bạn đã chỉ định hay không. Nếu thẻ EMatch khớp, thì mục đó sẽ không 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 đó cho biết mục bạn đã truy xuất đã được cập nhật.
Nếu ETag không khớp, thì 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 Google Data API.
Xử lý hàng loạt
Yêu cầu hàng loạt giúp khách hàng của bạn thực hiện nhiều thao tác trong một yêu cầu, thay vì gửi từng thao tác.
Máy chủ sẽ thực hiện nhiều thay đổi đã 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á trạng thái thành công hay thất bại của mỗi toán tử. Để biết thêm thông tin chi tiết về quá trình xử lý hàng loạt trong API Dữ liệu của Google, hãy xem bài viết Xử lý hàng loạt bằng API Dữ liệu của Google
Mọi toán tử trong một nguồn cấp dữ liệu hàng loạt đều có phần tử <id>, ngoại trừ các thao tác chèn.
Phần tử này giống với URL yêu cầu mà bạn thường sử dụng khi cập nhật, xóa hoặc truy vấn nguồn cấp nội dung.
Ví dụ: nếu bạn đang cập nhậ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 liên quan.
Nó được dùng để xác định mục tiêu. Các mục nhập mới chưa 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 tương ứng.
Để tạo yêu cầu hàng loạt, hãy tạo nguồn cấp dữ liệu hàng loạt và gửi một HTTP POST
đến 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 minh họa cách truy vấn, chèn, cập nhật và xoá mục nhập 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 phép toán:
<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>