vimeo直接上传表格

时间:2018-08-28 04:26:10

标签: vimeo vimeo-api

根据Vimeo,可以将上载直接发送到他们的服务器,而无需使用站点的托管服务器。

https://help.vimeo.com/hc/en-us/articles/224970068-Can-I-upload-directly-to-Vimeo-and-skip-my-server-entirely-

带有文档: https://developer.vimeo.com/api/upload/videos#http-post-uploading

但是,我没有找到任何示例,或者我能理解该怎么做

1 个答案:

答案 0 :(得分:1)

已解决

下载API Vimeo:API Vimeo

加载API:File: vimeo_init.php

ini_set('display_errors', 'On');
error_reporting(E_ALL);
// Load the autoloader
if (file_exists('/vimeo/autoload.php')) {
    // Composer
    require_once('/vimeo/autoload.php');
} else {
    // Custom
    require_once(__DIR__ . '/vimeo/autoload.php');
}
// Load the configuration file.
if (!function_exists('json_decode')) {
    throw new Exception(
        'We could not find `json_decode`. `json_decode` is found in PHP 5.2 and up, but not found on many Linux ' .
        'systems due to licensing conflicts. If you are running Ubuntu try `sudo apt-get install php5-json`.'
    );
}
$config = json_decode(file_get_contents(__DIR__ . '/vimeo_config.json'), true);
if (empty($config['client_id']) || empty($config['client_secret'])) {
    throw new Exception(
        'We could not locate your client id or client secret in "' . __DIR__ . '/vimeo_config.json". Please create one, ' .
        'and reference config.json.example'
    );
}
return $config;

配置API密钥:File vimeo_config.json

{
    "client_id" : "",
    "client_secret" : "",
    "access_token" : ""
}

文件POST PHP:File Upload Video

use Vimeo\Vimeo;
use Vimeo\Exceptions\VimeoUploadException;
$config = require(__DIR__ . '/vimeo_init.php');


$files =  array($_FILES['video_arquivo']['tmp_name']); //array_shift($files);
if (empty($config['access_token'])) {
    throw new Exception(
        'You can not upload a file without an access token. You can find this token on your app page, or generate ' .
        'one using `auth.php`.'
    );
}

$lib = new Vimeo($config['client_id'], $config['client_secret'], $config['access_token']);
$uploaded = array();

foreach ($files as $file_name) {
    try {
        $uri = $lib->upload($file_name, array(
            'name' => 'titulo',
            'description' => 'descricao'
        ));

        $video_data = $lib->request($uri);

        if ($video_data['status'] == 200) {
            $video_vimeo = $video_data['body']['link'];
        }

        $uploaded[] = array('file' => $file_name, 'api_video_uri' => $uri, 'link' => $link);
    } catch (VimeoUploadException $e) {
        $result["is_valid"] = false;
        $result["message"] = $e->getMessage();
    }
}