форма прямой загрузки vimeo - PullRequest
0 голосов
/ 28 августа 2018

Согласно 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 голосов
/ 28 августа 2018

Решено

Загрузить 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();
    }
}
...