我们正在更新 Data API,以便与 YouTube 统计 Shorts 短视频观看次数的方式保持一致。
了解详情
Activities: insert
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
为特定频道发布公告。(提交请求的用户必须获得授权才能代表频道行事。)
注意:虽然 activity
资源可以包含有关用户对视频进行评分或将视频标记为喜好视频等操作的信息,但您需要使用其他 API 方法来生成这些 activity
资源。例如,您可以使用该 API 的 videos.rate()
方法对视频进行评分,并使用 playlistItems.insert()
方法将视频标记为喜爱。
配额影响:对该方法的调用会产生 50 个单位的配额费用。
请求
HTTP 请求
POST https://www.googleapis.com/youtube/v3/activities
授权
此请求需要获得以下至少一个范围的授权(详细了解身份验证和授权)。
范围 |
https://www.googleapis.com/auth/youtube |
https://www.googleapis.com/auth/youtube.force-ssl |
参数
下表列出了此查询支持的参数。列出的所有参数均为查询参数。
参数 |
必需参数 |
part |
string
在此操作中,part 参数有两个用途。用于标识写入操作将设置的属性以及 API 响应将包含的属性。
以下列表包含您可以包含在参数值中的 part 名称:
contentDetails
id
snippet
|
请求正文
在请求正文中提供活动资源。
对于该资源:
-
您必须为以下属性指定值:
-
您可以为以下属性设置值:
snippet.description
contentDetails.bulletin.resourceId
响应
如果成功,此方法将在响应正文中返回一项活动资源。
错误
下表列出了 API 在响应对此方法的调用时可能会返回的错误消息。如需了解详情,请参阅错误消息文档。
错误类型 |
错误详情 |
说明 |
badRequest (400) |
bulletinTextRequired |
请求必须使用 snippet 对象的 description 属性来提供公告帖子的文本。 |
badRequest (400) |
invalidMetadata |
kind 属性与所提供的 ID 类型不匹配。 |
forbidden (403) |
forbidden |
相应请求未获得适当的授权。 |
notFound (404) |
playlistNotFound |
YouTube 找不到您尝试与公告帖子关联的视频。检查 contentDetails.bulletinPosted.playlistId 属性的值。 |
notFound (404) |
videoNotFound |
YouTube 找不到您尝试与公告帖子关联的视频。检查 contentDetails.bulletinPosted.videoId 属性的值。 |
userRateLimitExceeded (403) |
rateLimitExceeded |
由于您已超出配额,因此无法完成该请求。 |
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-21。
[null,null,["最后更新时间 (UTC):2025-08-21。"],[[["\u003cp\u003eYouTube's channel bulletin feature has been deprecated and is no longer supported.\u003c/p\u003e\n"],["\u003cp\u003eCreating an activity requires authorization with specific scopes, such as \u003ccode\u003ehttps://www.googleapis.com/auth/youtube\u003c/code\u003e or \u003ccode\u003ehttps://www.googleapis.com/auth/youtube.force-ssl\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003epart\u003c/code\u003e parameter in the request specifies which properties will be modified and included in the API response, such as \u003ccode\u003econtentDetails\u003c/code\u003e, \u003ccode\u003eid\u003c/code\u003e, and \u003ccode\u003esnippet\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe request body must include an activity resource, and it is required to provide a value for \u003ccode\u003esnippet.description\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThis method call has a quota cost of 50 units, and exceeding the quota will result in a \u003ccode\u003euserRateLimitExceeded\u003c/code\u003e error.\u003c/p\u003e\n"]]],["The YouTube channel bulletin feature is deprecated. The API's `activities.insert` method allows posting to a channel. This requires authorization and has a quota cost of 50 units. You must provide `snippet.description` for the bulletin text in the request body. Key parameters include `part`, and the response returns an `activity` resource. Errors can occur due to bad requests, invalid metadata, authorization issues, or exceeding quota limits.\n"],null,["# Activities: insert\n\n**YouTube has deprecated the channel bulletin feature, and this method is no longer supported.** \n\nFor more details, please see the [YouTube Help Center](https://support.google.com/youtube?p=channel-bulletins).\nPosts a bulletin for a specific channel. (The user submitting the request must be authorized to act on the channel's behalf.) \n\n**Note:** Even though an `activity` resource can contain information about actions like a user rating a video or marking a video as a favorite, you need to use other API methods to generate those `activity` resources. For example, you would use the API's [videos.rate()](/youtube/v3/docs/videos/rate) method to rate a video and the [playlistItems.insert()](/youtube/v3/docs/playlistItems/insert) method to mark a video as a favorite.\n\n**Quota impact:** A call to this method has a [quota cost](/youtube/v3/getting-started#quota) of 50 units.\n\nRequest\n-------\n\n### HTTP request\n\n```\nPOST https://www.googleapis.com/youtube/v3/activities\n```\n\n### Authorization\n\nThis request requires authorization with at least one of the following scopes ([read more about authentication and authorization](/youtube/v3/guides/authentication)).\n\n| Scope |\n|-----------------------------------------------------|\n| `https://www.googleapis.com/auth/youtube` |\n| `https://www.googleapis.com/auth/youtube.force-ssl` |\n\n### Parameters\n\nThe following table lists the parameters that this query supports. All of the parameters listed are query parameters.\n\n| Parameters ||\n|--------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|\n| **Required parameters** |||\n| `part` | `string` The **part** parameter serves two purposes in this operation. It identifies the properties that the write operation will set as well as the properties that the API response will include. The following list contains the `part` names that you can include in the parameter value: - `contentDetails` - `id` - `snippet` |\n\n### Request body\n\nProvide an [activity resource](/youtube/v3/docs/activities#resource) in the request body.\nFor that resource:\n\n- You must specify a value for these properties:\n\n - `snippet.description`\n- You can set values for these properties:\n\n - `snippet.description`\n - `contentDetails.bulletin.resourceId`\n\nResponse\n--------\n\nIf successful, this method returns an [activity resource](/youtube/v3/docs/activities#resource) in the response body.\n\nErrors\n------\n\nThe following table identifies error messages that the API could return in response to a call to this method. Please see the [error message](/youtube/v3/docs/errors) documentation for more detail.\n\n| Error type | Error detail | Description |\n|-------------------------------|------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `badRequest (400)` | `bulletinTextRequired` | The request must use the `snippet` object's `description` property to provide the text for the bulletin post. |\n| `badRequest (400)` | `invalidMetadata` | The `kind` property does not match the type of ID provided. |\n| `forbidden (403)` | `forbidden` | The request is not properly authorized. |\n| `notFound (404)` | `playlistNotFound` | YouTube cannot find the video that you are trying to associate with the bulletin post. Check the value of the `contentDetails.bulletinPosted.playlistId` property. |\n| `notFound (404)` | `videoNotFound` | YouTube cannot find the video that you are trying to associate with the bulletin post. Check the value of the `contentDetails.bulletinPosted.videoId` property. |\n| `userRateLimitExceeded (403)` | `rateLimitExceeded` | The request cannot be completed because you have exceeded your [quota](/youtube/v3/getting-started#quota). |"]]