チャンネルのメタデータを更新します。このメソッドは現在、channel
リソースの brandingSettings
および invideoPromotion
オブジェクトとその子プロパティに対する更新のみをサポートすることに注意してください。
今すぐ試すまたは例を見る。
リクエスト
HTTP リクエスト
PUT https://www.googleapis.com/youtube/v3/channels
承認
このリクエストは、最低でも以下のスコープの 1 つによって承認される必要があります(認証と承認の詳細については、こちらをご覧ください)。
スコープ |
---|
https://www.googleapis.com/auth/youtubepartner |
https://www.googleapis.com/auth/youtube |
パラメータ
下記の表は、このクエリでサポートされているパラメータの一覧です。このリストのパラメータはすべてクエリ パラメータです。
パラメータ | ||
---|---|---|
必須パラメータ | ||
part |
string この操作では、 part パラメータは 2 つの目的で使用されます。書き込み操作で設定されるプロパティの特定と API レスポンスに含まれるプロパティの特定です。現在、この API でパラメータ値に含めることができるのは id および invideoPromotion パーツのみです。このメソッドは、パラメータの値で指定された任意のパーツに含まれる変更可能なプロパティすべての既存の値よりも優先されますので、ご注意ください。 |
|
省略可能なパラメータ | ||
onBehalfOfContentOwner |
string このパラメータは、適切に承認されたリクエストでのみ使用できます。 onBehalfOfContentOwner パラメータは、認証済みユーザーが、このパラメータ値で指定されたコンテンツ所有者の代理人の役割を果たしていることを示します。このパラメータは、複数の YouTube チャンネルを所有、管理している YouTube コンテンツ パートナーを対象にしています。このパラメータを使用すると、コンテンツ所有者は一度認証されれば、すべての動画やチャンネル データにアクセスできるようになります。チャンネルごとに認証情報を指定する必要はありません。ユーザー認証に使用する実際の CMS アカウントは、指定された YouTube コンテンツ所有者にリンクされていなければなりません。 |
リクエストの本文
リクエストの本文にはチャンネルのリソースを指定します。 このリソースでは、次の点に注意してください。
-
以下のプロパティの値を指定する必要があります。
id
-
以下のプロパティの値を設定することができます。
invideoPromotion.position.type
invideoPromotion.position.cornerPosition
brandingSettings.image.bannerExternalUrl
invideoPromotion.defaultTiming.type
invideoPromotion.defaultTiming.offsetMs
invideoPromotion.items[].id.type
invideoPromotion.items[].id.videoId
invideoPromotion.items[].timing.type
invideoPromotion.items[].timing.offsetMs
更新リクエストを送信する場合、既に値が設定されているプロパティの値を指定していないと、そのプロパティの既存の値が削除されます。
レスポンス
成功すると、このメソッドはレスポンスの本文でチャンネルのリソースを返します。
例
注: 以下のコード サンプルは、サポートされているプログラミング言語すべてについて表したものではありません。サポートされている言語の一覧については、クライアント ライブラリのドキュメントを参照してください。
Java
この例では、Java クライアント ライブラリを使用しています。
-
AddFeaturedVideo.java
/* * Copyright (c) 2013 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the License for the specific language governing permissions and limitations under * the License. */ package com.google.api.services.samples.youtube.cmdline.youtube_cmdline_addfeaturedvideo_sample; import com.google.api.client.auth.oauth2.Credential; import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp; import com.google.api.client.extensions.java6.auth.oauth2.FileCredentialStore; import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver; import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow; import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; import com.google.api.client.googleapis.json.GoogleJsonResponseException; import com.google.api.client.http.HttpTransport; import com.google.api.client.http.javanet.NetHttpTransport; import com.google.api.client.json.JsonFactory; import com.google.api.client.json.jackson2.JacksonFactory; import com.google.api.services.youtube.YouTube; import com.google.api.services.youtube.model.*; import com.google.common.collect.Lists; import java.io.File; import java.io.IOException; import java.math.BigInteger; import java.util.List; /** * This program adds a featured video to a channel via the Invideo Programming API. * * @author Ikai Lan <ikai@google.com> */ public class AddFeaturedVideo { /** * Global instance of the HTTP transport. */ private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport(); /** * Global instance of the JSON factory. */ private static final JsonFactory JSON_FACTORY = new JacksonFactory(); /** * Global instance of Youtube object to make all API requests. */ private static YouTube youtube; /** * Authorizes the installed application to access user's protected data. * * @param scopes list of scopes needed to run youtube upload. */ private static Credential authorize(List<String> scopes) throws IOException { // Load client secrets. GoogleClientSecrets clientSecrets = GoogleClientSecrets.load( JSON_FACTORY, AddFeaturedVideo.class.getResourceAsStream("/client_secrets.json")); // Checks that the defaults have been replaced (Default = "Enter X here"). if (clientSecrets.getDetails().getClientId().startsWith("Enter") || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) { System.out.println( "Enter Client ID and Secret from https://console.developers.google.com/project/_/apiui/credential" + "into youtube-cmdline-addfeaturedvideo-sample/src/main/resources/client_secrets.json"); System.exit(1); } // Set up file credential store. FileCredentialStore credentialStore = new FileCredentialStore( new File(System.getProperty("user.home"), ".credentials/youtube-api-addfeaturedvideo.json"), JSON_FACTORY); // Set up authorization code flow. GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder( HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, scopes).setCredentialStore(credentialStore) .build(); // Build the local server and bind it to port 8080 LocalServerReceiver localReceiver = new LocalServerReceiver.Builder().setPort(8080).build(); // Authorize. return new AuthorizationCodeInstalledApp(flow, localReceiver).authorize("user"); } /** * This is a very simple code sample that looks up a user's channel, then features the most recently * uploaded video in the bottom left hand corner of every single video in the channel. * * @param args command line args (not used). */ public static void main(String[] args) { // An OAuth 2 access scope that allows for full read/write access. List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube"); try { // Authorization. Credential credential = authorize(scopes); // YouTube object used to make all API requests. youtube = new YouTube.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName( "youtube-cmdline-addfeaturedvideo-sample").build(); // Fetch the user's channel. We also fetch the uploads playlist so we can use this later // to find the most recently uploaded video ChannelListResponse channelListResponse = youtube.channels().list("id,contentDetails") .setMine(true) .setFields("items(contentDetails/relatedPlaylists/uploads,id)") .execute(); // This assumes the user has a channel already. If the user does not have a channel, this should // throw a GoogleJsonResponseException explaining the issue Channel myChannel = channelListResponse.getItems().get(0); String channelId = myChannel.getId(); String uploadsPlaylistId = myChannel.getContentDetails().getRelatedPlaylists().getUploads(); // Fetch the most recently uploaded video PlaylistItemListResponse playlistItemListResponse = youtube.playlistItems().list("snippet") .setPlaylistId(uploadsPlaylistId) .setFields("items/snippet") .execute(); String featuredVideoId; if (playlistItemListResponse.getItems().isEmpty()) { // There are no videos on the channel. Therefore, we cannot feature a video. Exit. System.out.println("Channel contains no videos. Featuring a default video instead from the Google Developers channel."); featuredVideoId = "w4eiUiauo2w"; } else { // The latest video should be the first video in the playlist response PlaylistItem featuredVideo = playlistItemListResponse.getItems().get(0); featuredVideoId = featuredVideo.getSnippet() .getResourceId() .getVideoId(); System.out.println("Featuring video: " + featuredVideo.getSnippet().getTitle()); } // Feature this video on the channel via the Invideo programming API // This describes the position of the video. Valid positions are bottomLeft, bottomRight, topLeft and // topRight InvideoPosition invideoPosition = new InvideoPosition(); invideoPosition.setCornerPosition("bottomLeft"); invideoPosition.setType("corner"); // The allowed offsets are offsetFromEnd and offsetFromStart, with offsetMs being an offset in milliseconds InvideoTiming invideoTiming = new InvideoTiming(); invideoTiming.setOffsetMs(BigInteger.valueOf(15000l)); invideoTiming.setType("offsetFromEnd"); // Represents the type of promotion. In this case, a video with a video ID PromotedItemId promotedItemId = new PromotedItemId(); promotedItemId.setType("video"); promotedItemId.setVideoId(featuredVideoId); // Construct the Invidideo promotion InvideoPromotion invideoPromotion = new InvideoPromotion(); invideoPromotion.setPosition(invideoPosition); invideoPromotion.setTiming(invideoTiming); invideoPromotion.setItems(Lists.newArrayList(promotedItemId)); // Now let's add the invideo promotion to the channel Channel channel = new Channel(); channel.setId(channelId); channel.setInvideoPromotion(invideoPromotion); // Make the API call Channel updateChannelResponse = youtube.channels() .update("invideoPromotion", channel) .execute(); // Print out returned results. System.out.println("\n================== Updated Channel Information ==================\n"); System.out.println("\t- Channel ID: " + updateChannelResponse.getId()); InvideoPromotion promotion = updateChannelResponse.getInvideoPromotion(); System.out.println("\t- Invideo promotion video ID: " + promotion.getItems() .get(0) .getVideoId()); System.out.println("\t- Promotion position: " + promotion.getPosition().getCornerPosition()); System.out.println("\t- Promotion timing: " + promotion.getTiming().getOffsetMs() + " Offset: " + promotion.getTiming().getType()); } catch (GoogleJsonResponseException e) { System.err.println("GoogleJsonResponseException code: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage()); e.printStackTrace(); } catch (IOException e) { System.err.println("IOException: " + e.getMessage()); e.printStackTrace(); } } }
-
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.google.api.services.samples.youtube.cmdline</groupId> <artifactId>youtube-cmdline-addfeaturedvideo-sample</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>youtube-cmdline-addfeaturedvideo-sample</name> <url>http://maven.apache.org</url> <properties> <project.youtube.version>v3-rev56-1.15.0-rc</project.youtube.version> <project.http.version>1.15.0-rc</project.http.version> <project.oauth.version>1.15.0-rc</project.oauth.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <repositories> <repository> <id>google-api-services</id> <url>http://google-api-client-libraries.appspot.com/mavenrepo</url> </repository> </repositories> <dependencies> <!-- YouTube Data V3 support --> <dependency> <groupId>com.google.apis</groupId> <artifactId>google-api-services-youtube</artifactId> <version>${project.youtube.version}</version> </dependency> <dependency> <groupId>com.google.http-client</groupId> <artifactId>google-http-client-jackson2</artifactId> <version>${project.http.version}</version> </dependency> <dependency> <groupId>com.google.oauth-client</groupId> <artifactId>google-oauth-client-jetty</artifactId> <version>${project.oauth.version}</version> </dependency> <dependency> <groupId>com.google.collections</groupId> <artifactId>google-collections</artifactId> <version>1.0</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.2.1</version> <configuration> <mainClass>com.google.api.services.samples.youtube.cmdline.youtube_cmdline_addfeaturedvideo_sample.AddFeaturedVideo</mainClass> </configuration> </plugin> <!-- Forces Maven to use Java 1.6 --> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.6</target> <compilerArgument></compilerArgument> </configuration> </plugin> </plugins> </build> </project>
-
client_secrets.json
{ "installed": { "client_id": "Enter Client ID", "client_secret": "Enter Client Secret" } }
Python
この例では、Python クライアント ライブラリを使用しています。
#!/usr/bin/python import httplib2 import os import sys from apiclient.discovery import build from apiclient.errors import HttpError from oauth2client.client import flow_from_clientsecrets from oauth2client.file import Storage from oauth2client.tools import argparser, run_flow # The CLIENT_SECRETS_FILE variable specifies the name of a file that contains # the OAuth 2.0 information for this application, including its client_id and # client_secret. You can acquire an OAuth 2.0 client ID and client secret from # the Google API Console at # https://console.cloud.google.com/. # Please ensure that you have enabled the YouTube Data API for your project. # For more information about using OAuth2 to access the YouTube Data API, see: # https://developers.google.com/youtube/v3/guides/authentication # For more information about the client_secrets.json file format, see: # https://developers.google.com/api-client-library/python/guide/aaa_client_secrets CLIENT_SECRETS_FILE = "client_secrets.json" # This variable defines a message to display if the CLIENT_SECRETS_FILE is # missing. MISSING_CLIENT_SECRETS_MESSAGE = """ WARNING: Please configure OAuth 2.0 To make this sample run you will need to populate the client_secrets.json file found at: %s with information from the API Console https://console.cloud.google.com/ For more information about the client_secrets.json file format, please visit: https://developers.google.com/api-client-library/python/guide/aaa_client_secrets """ % os.path.abspath(os.path.join(os.path.dirname(__file__), CLIENT_SECRETS_FILE)) # This OAuth 2.0 access scope allows for full read/write access to the # authenticated user's account. YOUTUBE_SCOPE = "https://www.googleapis.com/auth/youtube" YOUTUBE_API_SERVICE_NAME = "youtube" YOUTUBE_API_VERSION = "v3" # If offsetMs is not valid, the API will throw an error VALID_OFFSET_TYPES = ("offsetFromEnd", "offsetFromStart",) def get_authenticated_service(args): flow = flow_from_clientsecrets(CLIENT_SECRETS_FILE, scope=YOUTUBE_SCOPE, message=MISSING_CLIENT_SECRETS_MESSAGE) storage = Storage("%s-oauth2.json" % sys.argv[0]) credentials = storage.get() if credentials is None or credentials.invalid: credentials = run_flow(flow, storage, args) return build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, http=credentials.authorize(httplib2.Http())) def add_featured_video(youtube, options): add_video_request = youtube.channels().update( part="invideoPromotion", # You can use the API Explorer to test API requests: # https://developers.google.com/youtube/v3/docs/channels/update#try-it body={ "invideoPromotion": { "items": [{ "id": { "type": "video", "videoId": options.video_id }, "timing": { "offsetMs": options.offset_ms, "type": options.offset_type } }], }, "id": options.channel_id }).execute() if __name__ == '__main__': argparser.add_argument("--channel-id", required=True, help="Channel ID of the channel to add a featured video") argparser.add_argument("--video-id", required=True, help="Video ID to feature on your channel") argparser.add_argument("--offset-ms", help="Offset in milliseconds to show video.", default="10000") argparser.add_argument("--offset-type", choices=VALID_OFFSET_TYPES, help="Whether the offset is from the beginning or end of video playback.", default=VALID_OFFSET_TYPES[0]) args = argparser.parse_args() youtube = get_authenticated_service(args) try: add_featured_video(youtube, args) except HttpError, e: print "An HTTP error %d occurred:\n%s" % (e.resp.status, e.content) else: print "Added featured video %s to channel %s." % ( args.video_id, args.channel_id)
エラー
次の表は、このメソッドを呼び出したときに API からレスポンスとして返される可能性のあるエラー メッセージの一覧です。詳細については、エラー メッセージのドキュメントを参照してください。
エラー タイプ | エラーの詳細 | 説明 |
---|---|---|
badRequest |
brandingValidationError |
brandingSettings オブジェクトに、検証できない値が含まれています。channels.list メソッドを使用して、このチャンネルに対して既に行われている設定を取得し、channels リソース ドキュメントのガイドラインに従ってプロパティの値を更新してください。 |
badRequest |
invalidBrandingOption |
指定したブランド設定のいずれかが存在しません。channels.list メソッドを使用して有効な値を取得し、channels リソース ドキュメントのガイドラインに従って設定を更新してください。 |
badRequest |
invalidCornerPosition |
プロモート アイテムの表示位置を特定するための、リクエスト メタデータにより指定されているコーナー位置が無効です。このリクエストによって送信されたリソースの invideoPromotion.position.cornerPosition プロパティの値を確認してください。 |
badRequest |
invalidItemType |
リクエスト メタデータにより、invideoPromotion 部に指定されたアイテム タイプが無効です。このリクエストによって送信されたリソースの invideoPromotion.items[].type プロパティの値を確認してください。 |
badRequest |
invalidPositionOffset |
動画プレーヤーでのプロモート アイテムの配置方法を決定するための、リクエスト メタデータにより指定されている位置タイプが無効です。このリクエストによって送信されたリソースの invideoPromotion.position.type プロパティの値を確認してください。 |
badRequest |
invalidTimingOffset |
リクエスト メタデータが、動画プレーヤーにプロモート アイテムを表示するタイミングを決定するために指定しているタイミング オフセットが無効です。このリクエストによって送信されたリソースの invideoPromotion.timing.offsetMs プロパティの値を確認してください。 |
badRequest |
invalidTimingType |
リクエスト メタデータが、動画プレーヤーにプロモート アイテムを表示するタイミングを決定するために指定しているタイミング メソッドが無効です。このリクエストによって送信されたリソースの invideoPromotion.timing.type プロパティの値を確認してください。 |
forbidden |
channelForbidden |
id パラメータで指定されたチャンネルは、リクエストをサポートしていません。またはリクエストが適切に認証されていません。 |
notFound |
channelNotFound |
id パラメータで指定されたチャンネルが見つかりません。または、このチャンネルにはブランド オプションがありません。 |
notFound |
unknownChannelId |
API リクエストが更新しようとしているチャンネルが見つかりません。このリクエストが送信した channel リソースの id プロパティの値をチェックして、チャンネル ID が正しいことを確認してください。 |
notFound |
unknownVideoId |
プロモート アイテムとして指定された動画 ID が見つかりません。 |
required |
requiredCornerPosition |
リクエスト メタデータでコーナーの位置を指定して、プレーヤー内のプロモート アイテムが表示される場所を YouTube が判断できるようにする必要があります。このリクエストが送信するリソースの invideoPromotion.position.cornerPosition プロパティの値を設定してください。 |
required |
requiredItemType |
リクエスト メタデータで、プロモート アイテムのタイプを指定する必要があります。このリクエストが送信するリソースの invideoPromotion.items[].type プロパティの値を設定してください。 |
required |
requiredPositionOffset |
リクエスト メタデータで位置タイプを指定して、プロモート アイテムの表示方法を YouTube が判断できるようにする必要があります。このリクエストが送信するリソースの invideoPromotion.position.type プロパティの値を設定してください。 |
required |
requiredTimingOffset |
リクエスト メタデータでタイミング オフセットを指定して、プロモート アイテムを表示するタイミングを YouTube が判断できるようにする必要があります。このリクエストが送信するリソースの invideoPromotion.timing.offsetMs プロパティの値を設定してください。 |
required |
requiredTimingType |
リクエスト メタデータでタイミング メソッドを指定して、プロモート アイテムを表示するタイミングを YouTube が判断できるようにする必要があります。このリクエストが送信するリソースの invideoPromotion.timing.type プロパティの値を設定してください。 |
required |
requiredVideoId |
プロモート アイテムを特定するため、リクエスト メタデータには動画 ID を指定する必要があります。 |
実際に試してみる
API Explorer を使用し、ライブ データに対してこのメソッドを呼び出して、API リクエストとレスポンスを確認してください。