php - 我从 youtube-api 收到“500 后端错误”和“400 无效元数据”
问题描述
我使用 PHP 通过 youtube-api 插入/更新视频的标题和描述,但我遇到了一些问题。
1. 当我使用 zh-Hant 或 zh-Hans 插入/更新视频的标题和描述时,我得到"500 Backend Error."
但是当我更改zh-Hant
和zh-Hans
时它可以工作zh-tw
和zh-cn
。
2."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;
}
解决方案
目前似乎不支持您使用的语言(zh-Hant & zh-Hans)。
要验证是否支持某种语言,您可以使用 i18nLanguages.list API。这是使用 API 资源管理器的示例请求。
推荐阅读
- spring - 如何在spring集成http入站网关中使用spring security
- javascript - 条卡元素中 CVV 编号的密码掩码
- r - 使用 TimeSeries_Generator 进行 LSTM 时间序列预测
- elasticsearch - Elasticsearch:访问由 filebeat 创建的多个索引
- javascript - 如何从 JS 函数调用 Bootstrap 弹出模型?
- django - django 3.0 异步 orm
- woocommerce - 订单状态变化时调用 api
- csv - 批处理脚本 - 根据文件名将列添加到 CSV
- javascript - 在大型 TypeScript 项目中共享类型的最佳方式是什么?
- alexa-skills-kit - ASK SDK V2 - .addAudioPlayDirective - 无元数据