Điều kiện tiên quyết
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.
Tài liệu này mô tả những việc bạn cần làm trước khi viết ứng dụng đầu tiên.
Tạo tài khoản Google
Bạn cần có Tài khoản Google để sử dụng API này.
Tài khoản của bạn phải có quyền thích hợp trong Search Console đối với một tài sản nhất định để
gọi phương thức đó trên tài sản đó. Ví dụ: để chạy searchAnalytics.query, bạn cần có quyền đọc trên thuộc tính đó.
Dùng thử Google Search Console
Tài liệu về API này giả định rằng bạn đã sử dụng Google Search Console và bạn đã quen thuộc với các khái niệm lập trình web cũng như các định dạng dữ liệu web.
Nếu bạn chưa từng sử dụng Google Search Console, hãy thử giao diện người dùng trước khi bắt đầu viết mã.
Mỗi API đại diện cho chức năng của báo cáo trong Search Console. Bạn nên
đọc tài liệu về báo cáo tương đương trước khi sử dụng API để hiểu được dữ liệu mà bạn nhận được.
Tạo một dự án và thông tin đăng nhập cho khách hàng của bạn
Trước khi có thể gửi yêu cầu đến Google Search Console, bạn cần cho Google biết về ứng dụng của mình và kích hoạt quyền truy cập vào API. Bạn có thể thực hiện việc này bằng cách sử dụng Bảng điều khiển API của Google để tạo một dự án.
Đây là một tập hợp có tên gồm các chế độ cài đặt và thông tin về quyền truy cập vào API, đồng thời đăng ký ứng dụng của bạn.
Tất cả API Search Console (ngoại trừ API Công cụ kiểm thử) đều yêu cầu thông tin đăng nhập OAuth2.
Hướng dẫn bắt đầu nhanh về Python và Java cung cấp thông tin chi tiết về cách tạo dự án và lấy thông tin đăng nhập cho ứng dụng của bạn.
Tìm hiểu kiến thức cơ bản về Kiến trúc chuyển trạng thái đại diện (REST)
Có 2 cách để gọi API:
Nếu quyết định không sử dụng thư viện ứng dụng, bạn cần nắm được kiến thức cơ bản về REST.
Kiến thức cơ bản về REST
REST là một kiểu kiến trúc phần mềm mang lại cách tiếp cận thuận tiện và nhất quán để yêu cầu và sửa đổi dữ liệu.
Thuật ngữ REST là viết tắt của "Đại diện chuyển trạng thái". Trong ngữ cảnh của API Google, nó đề cập đến việc sử dụng các động từ HTTP để truy xuất và sửa đổi bản trình bày dữ liệu do Google lưu trữ.
Trong hệ thống RESTful, các tài nguyên được lưu trữ trong kho dữ liệu; máy khách gửi yêu cầu yêu cầu máy chủ thực hiện một thao tác cụ thể (chẳng hạn như tạo, truy xuất, cập nhật hoặc xoá tài nguyên), còn máy chủ thực hiện thao tác và gửi phản hồi, thường ở dạng biểu diễn tài nguyên đã chỉ định.
Trong API RESTful của Google, ứng dụng chỉ định một hành động bằng cách sử dụng động từ HTTP như POST
, GET
, PUT
hoặc DELETE
. Phương thức này chỉ định tài nguyên bằng một URI duy nhất trên toàn hệ thống có dạng sau:
https://www.googleapis.com/apiName/apiVersion/resourcePath?parameters
Vì mọi tài nguyên API đều có URI riêng biệt có thể truy cập HTTP, nên REST cho phép lưu dữ liệu vào bộ nhớ đệm và được tối ưu hoá để hoạt động với cơ sở hạ tầng phân phối của web.
Bạn có thể thấy định nghĩa về phương thức trong tài liệu về các tiêu chuẩn HTTP 1.1 hữu ích; vì các định nghĩa này bao gồm nội dung kỹ thuật cho GET
, POST
, PUT
và DELETE
.
REST trong Google Search Console API
Các thao tác của Google Search Console API liên kết trực tiếp với các động từ HTTP REST.
Hầu hết URI API của Google Search Console có định dạng như sau:
VERB https://www.googleapis.com/webmasters/v3/resourcePath?parameters
Tập hợp đầy đủ các URI và động từ dùng cho mỗi phương pháp được cung cấp trong tổng quan về Tài liệu tham khảo API về Google Search Console.
Tìm hiểu thông tin cơ bản về JSON
Google Search Console API trả về dữ liệu ở định dạng JSON.
JSON (Ký hiệu đối tượng JavaScript) là một định dạng dữ liệu phổ biến, không phụ thuộc vào ngôn ngữ, cung cấp bản trình bày văn bản đơn giản của các cấu trúc dữ liệu tùy ý. Để biết thêm thông tin, hãy xem json.org.
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: 2024-07-23 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2024-07-23 UTC."],[[["\u003cp\u003eBefore using the Google Search Console API, you must have a Google Account with the necessary Search Console permissions.\u003c/p\u003e\n"],["\u003cp\u003eFamiliarize yourself with the Google Search Console user interface and its reports to understand the data the API provides.\u003c/p\u003e\n"],["\u003cp\u003eCreate a project in the Google API Console and obtain OAuth2 credentials to enable your client application's access to the API.\u003c/p\u003e\n"],["\u003cp\u003eUnderstand REST principles, particularly HTTP verbs and resource URIs, to interact with the API directly or choose to use client libraries.\u003c/p\u003e\n"],["\u003cp\u003eThe Google Search Console API uses JSON for data exchange, so understanding this format is essential for processing API responses.\u003c/p\u003e\n"]]],["Before creating a client application, obtain a Google Account with Search Console permissions. Familiarize yourself with Google Search Console's user interface and relevant report documentation. Create a Google API Console project to register your application and get OAuth2 credentials. If not using client libraries, understand REST basics, including HTTP verbs (GET, POST, PUT, DELETE) and URIs. Finally, learn JSON, the data format used by the Google Search Console API.\n"],null,["# Prerequisites\n\nThis document describes the things you should do before\nwriting your first client application.\n\nGet a Google Account\n--------------------\n\nYou need a [Google Account](https://www.google.com/accounts/NewAccount) to use this API.\nYour account must have the appropriate Search Console permission on a given property in order to\ncall that method on that property. For example, in order to run [searchAnalytics.query](/webmaster-tools/v1/searchanalytics/query)\nyou need read permissions on that property.\n\nTry out Google Search Console\n-----------------------------\n\nThis API documentation assumes that you've used [Google Search Console](https://search.google.com/search-console/), and that you're familiar with web programming concepts and web data formats.\n\nIf you haven't used Google Search Console, then try out the [user interface](https://search.google.com/search-console/) before starting to code.\nEach API represents the functionality of a report in Search Console. You should [read the documentation for the equivalent report](https://support.google.com/webmasters/topic/9456557) before using an API in order to understand the data you receive.\n\nCreate a project and credentials for your client\n------------------------------------------------\n\nBefore you can send requests to Google Search Console, you need to tell Google about your client and\nactivate access to the API. You do this by using the Google API Console to create a project,\nwhich is a named collection of settings and API access information, and register your application.\n\n\nAll Search Console APIs except the Testing Tools API require OAuth2 credentials.\nThe Python and Java quickstart guides provide details on how to create a project and get credentials for your client.\n\nUnderstand REST basics\n----------------------\n\nThere are two ways to invoke the API:\n\n- Sending HTTP requests and parsing the responses.\n- Using [client libraries](./libraries).\n\nIf you decide not to use client libraries, you'll need to understand the basics of REST.\n\n#### REST basics\n\nREST is a style of software architecture that provides a convenient and consistent approach to requesting and modifying data.\n\nThe term REST is short for \"[Representational State Transfer](https://en.wikipedia.org/wiki/Representational_state_transfer).\" In the context of Google APIs, it refers to using HTTP verbs to retrieve and modify representations of data stored by Google.\n\nIn a RESTful system, resources are stored in a data store; a client sends a request that the server perform a particular action (such as creating, retrieving, updating, or deleting a resource), and the server performs the action and sends a response, often in the form of a representation of the specified resource.\n\nIn Google's RESTful APIs, the client specifies an action using an HTTP verb such as `POST`, `GET`, `PUT`, or `DELETE`. It specifies a resource by a globally-unique URI of the following form: \n\n```\nhttps://www.googleapis.com/apiName/apiVersion/resourcePath?parameters\n```\n\nBecause all API resources have unique HTTP-accessible URIs, REST enables data caching and is optimized to work with the web's distributed infrastructure.\n\nYou may find the [method definitions](https://tools.ietf.org/html/rfc7231#section-4.3) in the HTTP 1.1 standards documentation useful; they include specifications for `GET`, `POST`, `PUT`, and `DELETE`.\n\n### REST in the Google Search Console API\n\nThe Google Search Console API operations map directly to REST HTTP verbs.\n\nThe format for most Google Search Console API URIs are something like this: \n\n```\nVERB https://www.googleapis.com/webmasters/v3/resourcePath?parameters\n```\n\nThe full set of URIs and verbs used for each method are given in the [Google Search Console API Reference](/webmaster-tools/v1/api_reference_index) overview.\n\nUnderstand JSON basics\n----------------------\n\nThe Google Search Console API returns data in JSON format.\n\n\n[JSON](http://en.wikipedia.org/wiki/JSON) (JavaScript Object Notation) is a common, language-independent data format that provides a simple text representation of arbitrary data structures. For more information, see [json.org](http://www.json.org/).\n\n\u003cbr /\u003e"]]