我们正在更新 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
|
请求正文
在请求正文中提供 activity 资源。
针对该资源:
-
您必须为以下属性指定一个值:
-
您可以为以下属性设置值:
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):2024-04-26。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2024-04-26。"],[[["YouTube's channel bulletin feature has been deprecated and is no longer supported."],["Creating an activity requires authorization with specific scopes, such as `https://www.googleapis.com/auth/youtube` or `https://www.googleapis.com/auth/youtube.force-ssl`."],["The `part` parameter in the request specifies which properties will be modified and included in the API response, such as `contentDetails`, `id`, and `snippet`."],["The request body must include an activity resource, and it is required to provide a value for `snippet.description`."],["This method call has a quota cost of 50 units, and exceeding the quota will result in a `userRateLimitExceeded` error."]]],["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"]]