我使用PHP通过youtube-api插入/更新了视频的标题和描述,但出现了一些问题。
1。
当我使用zh-Hant或zh-Hans插入/更新视频的标题和说明时,我得到"500 Backend Error."
但是,当我将zh-Hant
和zh-Hans
更改为zh-tw
和zh-cn
时,它可以工作。
2。
当我使用Italian(it)更新视频标题时,我得到"400 invalidMetadata"
。
我对此一无所知,因为在其他语言中都可以,并且在使用意大利语更新视频说明中也可以。
如何解决这些问题?
这是我的代码:
public function __construct()
{
$client = new \Google_Client();
$client->setAuthConfig(storage_path('key/youtube_key/client_secret.json'));
$client->setApplicationName("String System");
$client->setScopes('https://www.googleapis.com/auth/youtube.force-ssl');
$client->setAccessType('offline');
$client->setAccessToken(Cache::get('google_auth_token'));
$this->client = $client;
}
public function youtubeService($stringKey, $stringValue, $language)
{
$this->service = new \Google_Service_YouTube($this->client);
$this->stringKey = $stringKey;
$this->stringValue = $stringValue;
$this->language = $language;
$key = explode('_', $this->stringKey);
if (3 != count($key)) {
return;
}
list($videoName, $videoID, $type) = $key;
$this->videoName= $videoName;
$this->videoID = $videoID;
switch ($type) {
case 'title':
$this->updateTitle();
break;
case 'description':
$this->updateDesc();
break;
}
return;
}
private function updateTitle()
{
// get video list by video ID
$video = $this->service->videos->listVideos(
'snippet,localizations',
['id' => $this->videoID]
);
$videoInfo = $video->items[0];
// set video title of language
if (isset($videoInfo->localizations[$this->language])) {
$videoInfo->localizations[$this->language]->title =
$this->stringValue;
// check default language
if ($this->language === $videoInfo->snippet->defaultLanguage) {
$videoInfo->snippet->title = $this->stringValue;
}
} else {
$videoInfo->localizations[$this->language] = [
'title' => $this->stringValue,
'description' => 'description'
];
}
try {
// update video information
$this->service->videos->update(
'snippet,localizations',
$videoInfo
);
} catch (Exception $e) {
// do nothing and continue
}
return;
}
private function updateDesc()
{
// get video list by video ID
$video = $this->service->videos->listVideos(
'snippet,localizations',
['id' => $this->videoID]
);
$videoInfo = $video->items[0];
// set video description of language
if (isset($videoInfo->localizations[$this->language])) {
$videoInfo->localizations[$this->language]->description =
$this->stringValue;
// check default language
if ($this->language === $videoInfo->snippet->defaultLanguage) {
$videoInfo->snippet->description = $this->stringValue;
}
} else {
$videoInfo->localizations[$this->language] = [
'title' => 'title',
'description' => $this->stringValue
];
}
try {
// update video information
$this->service->videos->update(
'snippet,localizations',
$videoInfo
);
} catch (Exception $e) {
// do nothing and continue
}
return;
}
答案 0 :(得分:0)
目前似乎不支持您使用的语言(zh-Hant和zh-Hans)。
要验证是否支持某种语言,可以使用i18nLanguages.list API。这是使用API资源管理器的示例请求。