Ví dụ đơn giản về việc truy xuất nguồn cấp dữ liệu JSON qua API dữ liệu bảng tính
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Cảnh báo: Trang này giới thiệu về các API cũ của Google, API dữ liệu của Google; trang này chỉ liên quan đến các API được liệt kê trong thư mục API dữ liệu của Google, nhiều API trong số này đã được thay thế bằng các API mới hơn. Để biết thông tin về một API mới cụ thể, hãy xem tài liệu của API mới. Để biết thông tin về việc uỷ quyền cho các yêu cầu bằng một API mới hơn, hãy xem phần Xác thực và ủy quyền tài khoản Google.
Giới thiệu
Mẫu này minh hoạ việc hiển thị nguồn cấp dữ liệu danh sách hoặc ô cho một trang tính cụ thể trong bảng tính bằng định dạng đầu ra JSON do API dữ liệu bảng tính cung cấp. Việc này cho phép bạn truy vấn danh sách công khai hoặc nguồn cấp dữ liệu di động của bảng tính và nhận được mục nhập kết quả dưới dạng đối tượng JSON. Để sử dụng nguồn cấp dữ liệu JSON mới, hãy tạo một phần tử tập lệnh có giá trị src
là
http://spreadsheets.google.com/feeds/feed/key/worksheet/public/basic?alt=json-in-script&callback=myFunc
trong đó feed
là loại nguồn cấp dữ liệu, key
là khoá của bảng tính mà bạn muốn truy xuất, worksheet
là giá trị nhận dạng vị trí hoặc duy nhất của trang tính và myFunc
là tên của hàm callback được truyền đối tượng JSON. Để biết thêm thông tin về việc hỗ trợ đầu ra JSON cho các API Dữ liệu của Google, vui lòng xem tài liệu hỗ trợ đầu ra JSON của chúng tôi.
Lưu ý: Việc truy xuất nguồn cấp dữ liệu không có xác thực chỉ được hỗ trợ cho các bảng tính đã xuất bản.
Lưu ý: Bạn có thể dùng các loại nguồn cấp dữ liệu cũng như giá trị chế độ hiển thị và chế độ chiếu khác để hỗ trợ đầu ra JSON. Để biết thêm thông tin về các loại nguồn cấp dữ liệu khác cũng như giá trị chế độ hiển thị và chế độ chiếu, vui lòng xem tài liệu về API dữ liệu bảng tính.
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2023-03-01 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2023-03-01 UTC."],[],[],null,["# Simple example of retrieving JSON feeds from Spreadsheets Data API\n\n**Warning** : This page is about Google's older APIs, the Google Data APIs; it's relevant only to the APIs that are listed in the [Google Data APIs directory](/gdata/docs/directory), many of which have been replaced with newer APIs. For information about a specific new API, see the new API's documentation. For information about authorizing requests with a newer API, see [Google Accounts Authentication and Authorization](/accounts).\n| Version v4 of the [Google Sheets API](/sheets) is now available! This [migration guide](/sheets/guides/migration) shows how to update applications to use v4.\n\n### Introduction\n\nThis sample demonstrates displaying a list or cells feed for a particular worksheet in a spreadsheet using the JSON output format provided by the Spreadsheets Data API. This allows you to query a spreadsheet's public list or cell feed and get the resulting entries returned as JSON objects. To use the new JSON feed, create a script element whose `src` value is\n\u003e `http://spreadsheets.google.com/feeds/`**feed** `/`**key** `/`**worksheet** `/public/basic?alt=json-in-script&callback=`**myFunc**\n\nwhere **`feed`** is the type of feed, **`key`** is the key of the spreadsheet you want to retrieve, the **`worksheet`** is the positional or unique identifier of the worksheet, and **`myFunc`** is the name of your callback function that is passed the JSON object. For more information on JSON output support for Google Data APIs please see our [JSON output support documentation](/gdata/json).\n\n**Note:** Retrieving a feed without authentication is only supported for published spreadsheets.\n\n**Note:** Other feed types and visibility and projection values may be used with JSON output support. For more information on other feed types, and visibility and projection values please see the [Spreadsheets Data API](/google-apps/spreadsheets) documentation.\n\n### Demo\n\nSpreadsheet: http://spreadsheets.google.com/feeds/ list cells / / /public/values OK"]]