使用Vimeo API上传字幕

时间:2019-05-21 01:17:16

标签: php vimeo vimeo-api

你能帮我吗?我正在尝试使用Vimeo API字幕通过PHP上传到我的视频。

以下是Vimeo-api文档:https://developer.vimeo.com/api/upload/texttracks

不幸的是,没有关于使用PHP上传Vimeo字幕的主题,而且Vimeo没有为新用户提供任何代码示例。

我以这种方式工作:

include __DIR__ . '/Vimeo/autoload.php';

// The client id and client secret needed to use the vimeo API
$clientId = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
$clientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

// when getting an auth token we need to provide the scope
// all possible scopes can be found here https://developer.vimeo.com/api/authentication#supported-scopes
$scope = "public";

// The id of the user
$userId = 99999999;

// initialize the vimeo library
$lib = new \Vimeo\Vimeo($clientId, $clientSecret);

// request an auth token (needed for all requests to the Vimeo API)
$token = $lib->clientCredentials($scope);

// set the token
$lib->setToken('xxxxxxxxxxxxxxxxxxxxxxx');

// request video data
$videos = $lib->request("/me/videos/9999999");

// pretty print output
echo '<pre>' . var_export($videos, true) . '</pre>';

例如,根据vimeo-api-doc,对于字幕,输出如下所示:

...
'texttracks' => 
    array (
      'uri' => '/videos/9999999/texttracks',
      'options' => 
      array (
        0 => 'GET',
        1 => 'POST',
      ),
      'total' => 0,
    ),
...
...

所以,现在,我不知道下一步,甚至再次阅读vimeo开发人员。页以查看下一步,但我迷路了。

您能帮我解决这个问题吗?

谢谢。

1 个答案:

答案 0 :(得分:1)

首先,https://developer.vimeo.com/api/upload/texttracks处的Vimeo文档过时了,他们尚未更新它,因此无法正常工作!我浏览了Vimeo.php源代码,发现了一个未记录的方法,名为uploadTexttrack,这是内部文档和函数原型:

 /**
 * Uploads a text track.
 *
 * @link https://developer.vimeo.com/api/upload/texttracks
 * @param string $texttracks_uri The text tracks uri that we are adding our text track to
 * @param string $file_path The path to your text track file
 * @param string $track_type The type of your text track
 * @param string $language The language of your text track
 * @return string The URI of the uploaded text track.
 * @throws VimeoRequestException
 * @throws VimeoUploadException
 */
public function uploadTexttrack($texttracks_uri, $file_path, $track_type, $language)

这是我的测试代码,看起来似乎很棒,请注意,VTT或SRT文件具有指向脚本的相对路径,并且CC名称从$ file_path中提取为basename()。视频ID为“ 453355865”。感谢Vimeo保存我的A ??!我有130个需要以下14种语言的视频,以满足在Covid 19期间在家中就学的孩子的特殊需求。我在一个学校系统工作,在这个系统中,许多父母因为他们不懂英语而无法帮助那里的孩子。

        <?php
    include '../vimeo/vendor/autoload.php';
    use Vimeo\Vimeo;
    use Vimeo\Exceptions;
    use Vimeo\Exceptions\VimeoUploadException;
    $client_id = 'your client id';
    $client_secret = 'your client secret';
    $access_token = 'your access token';
    $lib = new Vimeo($client_id, $client_secret, $access_token);
    $videos = $lib->uploadTexttrack("/videos/453355865/texttracks", "vtt/Circles 1107 My Acquaintances.English.vtt", "captions", "en-US");
    $videos = $lib->uploadTexttrack("/videos/453355865/texttracks", "vtt/Circles 1107 My Acquaintances.Amharic.vtt", "captions", "am");
    $videos = $lib->uploadTexttrack("/videos/453355865/texttracks", "vtt/Circles 1107 My Acquaintances.Arabic.vtt", "captions", "ar");
    $videos = $lib->uploadTexttrack("/videos/453355865/texttracks", "vtt/Circles 1107 My Acquaintances.Chinese Simplified.vtt", "captions", "zh-CN");
    $videos = $lib->uploadTexttrack("/videos/453355865/texttracks", "vtt/Circles 1107 My Acquaintances.French.vtt", "captions", "fr");
    $videos = $lib->uploadTexttrack("/videos/453355865/texttracks", "vtt/Circles 1107 My Acquaintances.German.vtt", "captions", "de");
    $videos = $lib->uploadTexttrack("/videos/453355865/texttracks", "vtt/Circles 1107 My Acquaintances.Hindi.vtt", "captions", "hi");
    $videos = $lib->uploadTexttrack("/videos/453355865/texttracks", "vtt/Circles 1107 My Acquaintances.Japanese.vtt", "captions", "ja");
    $videos = $lib->uploadTexttrack("/videos/453355865/texttracks", "vtt/Circles 1107 My Acquaintances.Korean.vtt", "captions", "ko");
    $videos = $lib->uploadTexttrack("/videos/453355865/texttracks", "vtt/Circles 1107 My Acquaintances.Mongolian.vtt", "captions", "mn");
    $videos = $lib->uploadTexttrack("/videos/453355865/texttracks", "vtt/Circles 1107 My Acquaintances.Portuguese.vtt", "captions", "pt");
    $videos = $lib->uploadTexttrack("/videos/453355865/texttracks", "vtt/Circles 1107 My Acquaintances.Punjabi.vtt", "captions", "pa");
    $videos = $lib->uploadTexttrack("/videos/453355865/texttracks", "vtt/Circles 1107 My Acquaintances.Russian.vtt", "captions", "ru");
    $videos = $lib->uploadTexttrack("/videos/453355865/texttracks", "vtt/Circles 1107 My Acquaintances.Spanish.vtt", "captions", "es");
    ?>