สิ่งที่ต้องดำเนินการก่อน
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เอกสารนี้อธิบายสิ่งที่คุณควรทำก่อนเขียนแอปพลิเคชันไคลเอ็นต์แรก
รับบัญชี Google
คุณต้องมีบัญชี Google เพื่อใช้ API นี้
บัญชีของคุณต้องมีสิทธิ์ Search Console ที่เหมาะสมในพร็อพเพอร์ตี้หนึ่งๆ จึงจะเรียกใช้เมธอดนั้นในพร็อพเพอร์ตี้นั้นได้ ตัวอย่างเช่น คุณต้องมีสิทธิ์อ่านในพร็อพเพอร์ตี้นั้นเพื่อเรียกใช้ searchAnalytics.query
ลองใช้ Google Search Console
เอกสารประกอบเกี่ยวกับ API นี้จะถือว่าคุณใช้ Google Search Console และคุ้นเคยกับแนวคิดการเขียนโปรแกรมเว็บและรูปแบบข้อมูลเว็บ
หากคุณไม่เคยใช้ Google Search Console ให้ลองใช้อินเทอร์เฟซผู้ใช้ก่อนเริ่มเขียนโค้ด
API แต่ละรายการจะแสดงฟังก์ชันการทำงานของรายงานใน Search Console คุณควร
อ่านเอกสารประกอบสำหรับรายงานที่เทียบเท่าก่อนใช้ API เพื่อทำความเข้าใจข้อมูลที่คุณได้รับ
สร้างโปรเจ็กต์และข้อมูลเข้าสู่ระบบสำหรับไคลเอ็นต์
คุณต้องแจ้งให้ Google ทราบเกี่ยวกับไคลเอ็นต์และเปิดใช้งานการเข้าถึง API ดังกล่าวก่อนจึงจะส่งคำขอไปยัง Google Search Console ได้ ซึ่งทำได้โดยใช้คอนโซล Google API เพื่อสร้างโปรเจ็กต์ ซึ่งเป็นคอลเล็กชันการตั้งค่าที่มีชื่อและข้อมูลการเข้าถึง API แล้วลงทะเบียนแอปพลิเคชันของคุณ
Search Console API ทั้งหมดยกเว้น Test Tools API ต้องใช้ข้อมูลเข้าสู่ระบบ OAuth2
คู่มือเริ่มใช้งานฉบับย่อสำหรับ Python และ Java จะให้รายละเอียดเกี่ยวกับวิธีสร้างโปรเจ็กต์และรับข้อมูลเข้าสู่ระบบสำหรับไคลเอ็นต์
ทำความเข้าใจพื้นฐานของ REST
การเรียก API ทำได้ 2 วิธีดังนี้
หากคุณตัดสินใจไม่ใช้ไลบรารีของไคลเอ็นต์ คุณจะต้องทำความเข้าใจพื้นฐานของ REST
ข้อมูลพื้นฐานเกี่ยวกับ REST
REST คือรูปแบบสถาปัตยกรรมซอฟต์แวร์ที่ให้วิธีการขอและแก้ไขข้อมูลที่สะดวกและสอดคล้องกัน
คำว่า REST เป็นคำสั้นๆ ของ "Assignational State Transfer" ในบริบทของ Google APIs หมายถึงการใช้คำกริยา HTTP เพื่อดึงและแก้ไขการนำเสนอข้อมูลที่ Google จัดเก็บไว้
ในระบบ RESTful ทรัพยากรจะจัดเก็บอยู่ในพื้นที่เก็บข้อมูล ไคลเอ็นต์จะขอให้เซิร์ฟเวอร์ดำเนินการบางอย่าง (เช่น สร้าง เรียก อัปเดต หรือลบทรัพยากร) และเซิร์ฟเวอร์จะดำเนินการดังกล่าวและส่งการตอบกลับ โดยมักจะอยู่ในรูปแบบเป็นตัวแทนของทรัพยากรที่ระบุ
ใน RESTful API ของ Google ไคลเอ็นต์จะระบุการทำงานโดยใช้คำกริยา HTTP เช่น POST
, GET
, PUT
หรือ DELETE
โดยจะระบุทรัพยากรตาม URI ที่ไม่ซ้ำกันทั่วโลกในรูปแบบต่อไปนี้
https://www.googleapis.com/apiName/apiVersion/resourcePath?parameters
เนื่องจากทรัพยากร API ทั้งหมดมี URI ที่เข้าถึงได้แบบ HTTP ที่ไม่ซ้ำกัน REST จึงทำให้เกิดการแคชข้อมูลและมีการปรับให้เหมาะสมเพื่อทำงานกับโครงสร้างพื้นฐานแบบกระจายตัวของเว็บ
คุณดูคำจำกัดความของเมธอดได้ในเอกสารประกอบของมาตรฐาน HTTP 1.1 ซึ่งมีประโยชน์เช่นกัน ซึ่งมีข้อกำหนดของ GET
, POST
, PUT
และ DELETE
REST ใน Google Search Console API
การดำเนินการของ Google Search Console API จะจับคู่กับคำกริยา HTTP ของ REST โดยตรง
รูปแบบ URI ของ Google Search Console API ส่วนใหญ่มีลักษณะดังนี้
VERB https://www.googleapis.com/webmasters/v3/resourcePath?parameters
ดูชุด URI และคำกริยาที่ใช้สำหรับแต่ละวิธีในภาพรวมข้อมูลอ้างอิงของ Google Search Console API
ทำความเข้าใจพื้นฐาน JSON
Google Search Console API จะแสดงข้อมูลในรูปแบบ JSON
JSON (JavaScript Object Notation) เป็นรูปแบบข้อมูลทั่วไปที่ไม่ขึ้นอยู่กับภาษา ซึ่งมีการนำเสนอแบบข้อความอย่างง่ายของโครงสร้างข้อมูลที่กำหนดเอง สำหรับข้อมูลเพิ่มเติม โปรดดู json.org
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2024-07-23 UTC
[null,null,["อัปเดตล่าสุด 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"]]