Method: spaces.create
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ạo một không gian. Có thể dùng để tạo một không gian có tên hoặc một cuộc trò chuyện nhóm trong Import mode
. Để biết ví dụ, hãy xem phần Tạo không gian.
Hỗ trợ các loại xác thực sau:
Khi xác thực dưới dạng một ứng dụng, bạn phải đặt trường space.customer
trong yêu cầu.
Khi xác thực dưới dạng một ứng dụng, ứng dụng Chat sẽ được thêm làm thành viên của không gian. Tuy nhiên, không giống như xác thực người dùng, ứng dụng Chat không được thêm làm người quản lý không gian. Theo mặc định, tất cả thành viên không gian đều có thể xoá ứng dụng Chat khỏi không gian. Để chỉ cho phép người quản lý không gian xoá ứng dụng khỏi một không gian, hãy đặt space.permission_settings.manage_apps
thành managersAllowed
.
Khi tạo không gian, việc có nhóm thành viên hay không phụ thuộc vào việc không gian đó được tạo trong Import mode
hay không:
- Chế độ nhập: Không có thành viên nào được tạo.
- Tất cả các chế độ khác: Người dùng gọi được thêm làm thành viên. Đây là:
- Chính ứng dụng đó khi sử dụng tính năng xác thực ứng dụng.
- Người dùng là con người khi sử dụng quy trình xác thực người dùng.
Nếu bạn nhận được thông báo lỗi ALREADY_EXISTS
khi tạo một không gian, hãy thử một displayName
khác. Một không gian hiện có trong tổ chức Google Workspace có thể đã sử dụng tên hiển thị này.
Yêu cầu HTTP
POST https://chat.googleapis.com/v1/spaces
URL sử dụng cú pháp Chuyển mã gRPC.
Tham số truy vấn
Thông số |
requestId |
string
Không bắt buộc. Giá trị nhận dạng riêng biệt cho yêu cầu này. Bạn nên dùng một UUID ngẫu nhiên. Việc chỉ định một mã yêu cầu hiện có sẽ trả về không gian được tạo bằng mã đó thay vì tạo một không gian mới. Việc chỉ định một mã yêu cầu hiện có từ cùng một ứng dụng Chat với một người dùng đã xác thực khác sẽ trả về lỗi.
|
Nội dung yêu cầu
Nội dung yêu cầu chứa một bản sao của Space
.
Nội dung phản hồi
Nếu thành công, nội dung phản hồi sẽ chứa một phiên bản mới được tạo của Space
.
Phạm vi uỷ quyền
Yêu cầu một trong các phạm vi OAuth sau:
https://www.googleapis.com/auth/chat.app.spaces.create
https://www.googleapis.com/auth/chat.app.spaces
https://www.googleapis.com/auth/chat.import
https://www.googleapis.com/auth/chat.spaces
https://www.googleapis.com/auth/chat.spaces.create
Để biết thêm thông tin, hãy xem Hướng dẫn uỷ quyền.
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: 2025-07-29 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-29 UTC."],[[["\u003cp\u003eCreates a space in Google Chat, which can be a named space or a group chat, supporting app and user authentication.\u003c/p\u003e\n"],["\u003cp\u003eWhen using app authentication, the space.customer field is required and no members are added in Import mode; otherwise, the calling user becomes a member.\u003c/p\u003e\n"],["\u003cp\u003eUses the \u003ccode\u003ePOST https://chat.googleapis.com/v1/spaces\u003c/code\u003e HTTP request to create a space and requires specific OAuth scopes for authorization.\u003c/p\u003e\n"],["\u003cp\u003eThe request body should contain a Space object and the response, if successful, will contain the newly created Space object.\u003c/p\u003e\n"],["\u003cp\u003eIf the displayName already exists, an \u003ccode\u003eALREADY_EXISTS\u003c/code\u003e error will be returned, suggesting to try a different displayName.\u003c/p\u003e\n"]]],["This content outlines how to create a space using the Chat API. Key actions include sending a `POST` request to `https://chat.googleapis.com/v1/spaces`. The request may include a unique `requestId` and must contain a `Space` instance in the body. Authentication can be app-based or user-based, requiring specific OAuth scopes. Space membership varies by import mode; no members in import mode, otherwise the caller is added. Response will contain new space information.\n"],null,["# Method: spaces.create\n\n- [HTTP request](#body.HTTP_TEMPLATE)\n- [Query parameters](#body.QUERY_PARAMETERS)\n- [Request body](#body.request_body)\n- [Response body](#body.response_body)\n- [Authorization scopes](#body.aspect)\n- [Try it!](#try-it)\n\nCreates a space. Can be used to create a named space, or a group chat in `Import mode`. For an example, see [Create a space](https://developers.google.com/workspace/chat/create-spaces).\n\nSupports the following types of [authentication](https://developers.google.com/workspace/chat/authenticate-authorize):\n\n- [App authentication](https://developers.google.com/workspace/chat/authenticate-authorize-chat-app) with [administrator approval](https://support.google.com/a?p=chat-app-auth) and one of the following authorization scopes:\n\n - `https://www.googleapis.com/auth/chat.app.spaces.create`\n - `https://www.googleapis.com/auth/chat.app.spaces`\n- [User authentication](https://developers.google.com/workspace/chat/authenticate-authorize-chat-user) with one of the following authorization scopes:\n\n - `https://www.googleapis.com/auth/chat.spaces.create`\n - `https://www.googleapis.com/auth/chat.spaces`\n - `https://www.googleapis.com/auth/chat.import` (import mode spaces only)\n\nWhen authenticating as an app, the `space.customer` field must be set in the request.\n\nWhen authenticating as an app, the Chat app is added as a member of the space. However, unlike human authentication, the Chat app is not added as a space manager. By default, the Chat app can be removed from the space by all space members. To allow only space managers to remove the app from a space, set `space.permission_settings.manage_apps` to `managersAllowed`.\n\nSpace membership upon creation depends on whether the space is created in `Import mode`:\n\n- **Import mode:** No members are created.\n- **All other modes:** The calling user is added as a member. This is:\n - The app itself when using app authentication.\n - The human user when using user authentication.\n\nIf you receive the error message `ALREADY_EXISTS` when creating a space, try a different `displayName`. An existing space within the Google Workspace organization might already use this display name.\n\n### HTTP request\n\n`POST https://chat.googleapis.com/v1/spaces`\n\nThe URL uses [gRPC Transcoding](https://google.aip.dev/127) syntax.\n\n### Query parameters\n\n| Parameters ||\n|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `requestId` | `string` Optional. A unique identifier for this request. A random UUID is recommended. Specifying an existing request ID returns the space created with that ID instead of creating a new space. Specifying an existing request ID from the same Chat app with a different authenticated user returns an error. |\n\n### Request body\n\nThe request body contains an instance of [Space](/workspace/chat/api/reference/rest/v1/spaces#Space).\n\n### Response body\n\nIf successful, the response body contains a newly created instance of [Space](/workspace/chat/api/reference/rest/v1/spaces#Space).\n\n### Authorization scopes\n\nRequires one of the following OAuth scopes:\n\n- `https://www.googleapis.com/auth/chat.app.spaces.create`\n- `https://www.googleapis.com/auth/chat.app.spaces`\n- `https://www.googleapis.com/auth/chat.import`\n- `https://www.googleapis.com/auth/chat.spaces`\n- `https://www.googleapis.com/auth/chat.spaces.create`\n\nFor more information, see the [Authorization guide](/workspace/chat/authenticate-authorize)."]]