YouTube에서 Shorts 동영상의 조회수를 집계하는 방식에 맞게 Data API를 업데이트하고 있습니다.
자세히 알아보기
구현: 부분 응답
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
다음 예는 YouTube Data API (v3)에서 부분 API 응답을 검색하는 방법을 보여줍니다.
참고: API의 시작하기 가이드에서 부분 요청 및 응답에 관해 자세히 알아보세요.
v3 API는 애플리케이션이 불필요한 데이터를 전송, 파싱, 저장하지 않도록 부분 리소스의 검색을 허용하고 실제로 요구합니다. 이를 통해 API가 네트워크, CPU, 메모리 리소스를 더 효율적으로 사용할 수 있도록 합니다.
이 API는 API 응답에 포함해야 하는 리소스 속성을 식별할 수 있는 두 가지 요청 매개변수인 part
및 fields
를 지원합니다. part
매개변수는 리소스를 삽입하거나 업데이트하는 API 요청에서 설정해야 하는 속성도 식별합니다.
업데이트 요청에서 이전에 값이 있었던 리소스 속성의 값을 지정하지 않으면 다음 조건이 참인 경우 기존 값이 삭제됩니다.
예
예를 들어 아래에 표시된 video
리소스를 업데이트하려고 한다고 가정해 보겠습니다. 아래에 표시된 모든 속성은 API를 통해 업데이트할 수 있으며 예와 관련 없는 리소스 속성은 생략되었습니다.
{
"snippet": {
"title": "Old video title",
"description": "Old video description",
"tags": ["keyword1","keyword2","keyword3"],
"categoryId: 22
},
"status": {
"privacyStatus": "private",
"publishAt": "2014-09-01T12:00:00.0Z",
"license": "youtube",
"embeddable": True,
"publicStatsViewable": True
}
}
videos.update
메서드를 호출하고 part
매개변수 값을 snippet
로 설정합니다. API 요청 본문에는 다음 리소스가 포함됩니다.
{
"snippet": {
"title": "New video title",
"tags": ["keyword1","keyword2","keyword3"],
"categoryId: 22
}
}
이 요청은 동영상 제목을 업데이트하고 설명을 삭제하며 태그 또는 카테고리 ID는 변경하지 않습니다. 요청에 snippet.description
속성의 값이 지정되지 않아 동영상 설명이 삭제됩니다.
part
매개변수 값에 요청에서 업데이트할 부분 중 하나로 status
가 포함되지 않았으므로 status
객체의 속성은 전혀 영향을 받지 않습니다. 실제로 API 요청 본문에 status
객체가 포함된 경우 API는 요청 본문에 예상치 못한 부분이 포함되어 있으므로 400 (Bad Request)
HTTP 응답을 반환합니다.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2024-11-23(UTC)
[null,null,["최종 업데이트: 2024-11-23(UTC)"],[[["\u003cp\u003eThe YouTube Data API (v3) requires retrieving partial resources to optimize data transfer, parsing, and storage.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003epart\u003c/code\u003e and \u003ccode\u003efields\u003c/code\u003e parameters enable users to specify which resource properties to include in API responses.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003epart\u003c/code\u003e parameter also dictates which properties are set during resource insertion or update requests.\u003c/p\u003e\n"],["\u003cp\u003eOmitting a previously valued property in an update request, within the specified \u003ccode\u003epart\u003c/code\u003e, will delete that property's value if modifiable.\u003c/p\u003e\n"],["\u003cp\u003eIncluding unexpected parts in an update request's body, meaning a part not listed in the \u003ccode\u003epart\u003c/code\u003e parameter, will result in a \u003ccode\u003e400 (Bad Request)\u003c/code\u003e HTTP response.\u003c/p\u003e\n"]]],["The YouTube Data API (v3) uses `part` and `fields` parameters to enable partial resource retrieval, improving efficiency by avoiding unnecessary data transfer. The `part` parameter identifies properties for retrieval and modification. When updating, omitting a previously valued property in the specified `part` results in its deletion. For example, updating a video resource's `snippet` part without including `description` deletes the description. Updating a property that is not in the part of the request being modified is not possible.\n"],null,["# Implementation: Partial responses\n\nThe following examples show how to retrieve partial API responses in the YouTube Data API (v3).\n\n**Note:** The API's [getting started](/youtube/v3/getting-started#partial) guide provides more detail about partial requests and responses.\n\nThe v3 API allows, and actually requires, the retrieval of partial resources so that applications avoid transferring, parsing, and storing unneeded data. This approach also ensures that the API uses network, CPU, and memory resources more efficiently.\n\nThe API supports two request parameters, `part` and `fields`, that enable you to identify the resource properties that should be included in API responses. The `part` parameter also identifies the properties that should be set by API requests that insert or update resources.\n\nNote that if an update request does not specify a value for a resource property that previously had a value, the existing value will be deleted if the following conditions are true:\n\n- The property's value can be modified by the request. (For example, when updating a `video` resource, you can update the value of the `snippet.description` property, but you cannot update the value of the `snippet.thumbnails` object.\n\n- The request's `part` parameter value identifies the resource part that contains the property.\n\n#### Example\n\nFor example, suppose you want to update the `video` resource shown below. (Note that all of the properties shown below can be updated via the API, and resource properties not relevant to the example have been omitted.) \n\n```\n{\n \"snippet\": {\n \"title\": \"Old video title\",\n \"description\": \"Old video description\",\n \"tags\": [\"keyword1\",\"keyword2\",\"keyword3\"],\n \"categoryId: 22\n },\n \"status\": {\n \"privacyStatus\": \"private\",\n \"publishAt\": \"2014-09-01T12:00:00.0Z\",\n \"license\": \"youtube\",\n \"embeddable\": True,\n \"publicStatsViewable\": True\n }\n}\n```\n\nYou call the [videos.update](/youtube/v3/docs/videos/update) method and set the `part` parameter value to `snippet`. The body of the API request contains the following resource: \n\n```\n{\n \"snippet\": {\n \"title\": \"New video title\",\n \"tags\": [\"keyword1\",\"keyword2\",\"keyword3\"],\n \"categoryId: 22\n }\n}\n```\n\nThis request updates the video's title, deletes its description, and does not change its tags or category ID. The video's description is deleted because the request does not specify a value for the `snippet.description` property.\n\nThe properties in the `status` object are not affected at all because the `part` parameter value did not include `status` as one of the parts that the request would update. In fact, if the body of the API request included the `status` object, the API would return a `400 (Bad Request)` HTTP response due to an [unexpected part](/youtube/v3/docs/errors#youtube.api.RequestContextError-badRequest-unexpectedPart) being included in the request body."]]