見出し画像

YouTube APIでlocalizationsを更新・削除する方法 / How to remove localizations from a video using YouTube API v3?

YouTube Data APIをつかえば動画のメタデータを編集できるし、それは簡単なことのはずやねんけど…


localizations(現地化)設定

YouTube動画には複数の言語でタイトルを設定できるローカライズ機能があって、うまく使えば日本だけでなくたくさんの国々で動画を視聴してもらえるかもしれへん。

Localaizations設定はStudioで手動でできるだけでなくAPIでもできて、マニュアルにはこう書いてある。

The property contains a read-only value. Use the localizations object to add, update, or delete localized titles.

https://developers.google.com/youtube/v3/docs/videos#snippet.localized

localizationsオブジェクトを使えば、現地化されたタイトルを追加、更新、削除できるとちゃんと書いてある。

不可解な現象

だがしかし、APIのリファレンスに沿ったリクエストを投げても設定が反映されないんである。

具体的には、設定済みの言語のタイトルや概要欄を更新しようとしても更新されない。さらに、設定済みの言語に対して削除もできない。

なんにもできないんである。

海外の同一事例

こちらのリンク先でも、ちょっと事情は違うながら、ローカライズ設定についての不可解な挙動を報告している。

そして自己解決のレスがある。現時点(投稿後11か月)でのview数は51 timesなので、ほぼ見られていない。ローカライズ機能はほとんど使われていないのかもしれない。

解決方法

いくらかの試行錯誤の末、localizationsについて再現性のある更新・削除方法を発見した。

この方法を理解するには、localizationsが「内部状態」を持つことを意識しなきゃならない。これはリファレンスに記載がなく、Studio上の表示にも反映されない。

更新・削除は以下のように行う。

まず、削除をAPIリクエスト(これで「変更不可状態」から「変更可能状態」に移行する)。

ついで、更新したければ新たなタイトル・ディスクリプションをAPIリクエスト。削除したければ改めて削除をAPIリクエスト(「変更可能状態」であれば、リクエストが通る)。

以上。

具体的には、localizationsから削除したい言語を削除したうえでAPIコール(※)。つづけてlocalizationsを設定してAPIコール(★)。

※をするとしないとで★の挙動が変わるので、なんらかの内部状態があるものと推定した。

自己解決について

さきほど掲載したstack overflowでも、いくらかの試行錯誤の上で問題解決を報告していた。だがこれは、試行によって無意識的に上記の状態変更をクリアできていたからのように思われる。

for English Readers

After some trial and error, we have found a reproducible update/delete method for localizations.

To understand how to do this, one must be aware that localizations have an "internal state". This is not mentioned in the reference and is not reflected in the display on Studio.

Updating and deleting is done as follows.

First, make an API request to delete (this will move it from "unchangeable" to "changeable" state).

Then, an API request is made for a new title and description to be updated. If you want to delete it, make another API request to delete it (if it is in the "changeable" state, the request will be approved).

That's all.

Specifically, delete the language you want to delete from the localizations and then make an API call (*1). Then, set the localizations and make an API call (*2).

Since the behavior of *2 changes whether *1 is done or not, we assumed that there is some kind of internal state.

この記事が気に入ったらサポートをしてみませんか?