require_once '../vimeo.php'; 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('./config.json'), true); 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']); // VOD film example // Create a new vod page $create_vod_film = $lib->request('/me/ondemand/pages', array('name' => 'myfilm', 'type' => 'film', 'content_rating' => 'safe', 'link' => 'myfilm', 'dommain_link' => 'myfilm', 'rent' => array('active' => true, 'price' => array('USD' => 5.0), 'period' => '24 hour'), 'buy' => array('active' => true, 'price' => array('USD' => 10.0))), 'POST'); // Set a Genre $genre = $lib->request('/ondemand/pages/myfilm/genres/art', array(), 'PUT'); // Add a video $uri = $lib->upload('myvideo.mp4'); $video_data = $lib->request($uri); $film_video = $lib->request('/ondemand/pages/myfilm' . $video_data['body']['uri'], array('type' => 'main'), 'PUT'); // Add a trailer $uri = $lib->upload('mytrailer.mp4'); $video_data = $lib->request($uri); $film_trailer = $lib->request('/ondemand/pages/myfilm' . $video_data['body']['uri'], array('type' => 'trailer'), 'PUT'); // Check to make sure the new video and trailer has been added to the vod page properly $check_video = $lib->request('/ondemand/pages/myfilm/videos', array('filter' => 'all', 'sort' => 'default')); print_r($check_video); // Add a poster to our vod page $response = $lib->uploadImage('/ondemand/pages/myfilm/pictures', './test.png'); $poster = $lib->request($response, array('active' => true), 'PATCH'); // Publish our new vod page - You can only publish after you all videos for your film have finished transcoding //$publish_video = $lib->request('/ondemand/pages/myfilm', array('publish' => array('active' => true)), 'PATCH'); //print_r($publish_video);
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']); // Get the args from the command line to see what files to upload. $files = $argv; array_shift($files); // Keep track of what we have uploaded. $uploaded = array(); // Send the files to the upload script. foreach ($files as $file_name) { // Update progress. print 'Uploading ' . $file_name . "\n"; try { // Send this to the API library. $uri = $lib->upload($file_name); // Now that we know where it is in the API, let's get the info about it so we can find the link. $video_data = $lib->request($uri); // Pull the link out of successful data responses. $link = ''; if ($video_data['status'] == 200) { $link = $video_data['body']['link']; } // Store this in our array of complete videos. $uploaded[] = array('file' => $file_name, 'api_video_uri' => $uri, 'link' => $link); } catch (VimeoUploadException $e) { // We may have had an error. We can't resolve it here necessarily, so report it to the user. print 'Error uploading ' . $file_name . "\n"; print 'Server reported: ' . $e->getMessage() . "\n"; } }