Last active
December 22, 2020 00:08
-
-
Save gdarko/edc59e3e42bc74aac693cb19f99d8bd3 to your computer and use it in GitHub Desktop.
How to use the Vimeo videos API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# Example 1 - Upload local video | |
$api = new WP_DGV_Api_Helper(); | |
$path = '/home/user/video.mp4'; | |
$params = array( | |
'name' => 'Cool Video', | |
'description' => 'Some description', | |
); | |
$result = $api->upload($path, $params); | |
if($result['response']) { | |
$uri = wvv_response_to_uri($result['response']); | |
$result = $this->db_helper->create_local_video( $params['name'], $params['description'], $uri); | |
if(is_wp_error($result)) { | |
// Handle errors. | |
} else { | |
// Continue. | |
} | |
# Example 2 - Upload remote video (Note: This is better way because you don't rely on upload_max_filesize and other constants. Vimeo will download the video from the provided url, however it needs to be public.) | |
$api = new WP_DGV_Api_Helper(); | |
$url = 'https://direct-path.com/video.mp4'; | |
$params = array( | |
'name' => 'Cool Video', | |
'description' => 'Some description', | |
'privacy' => array( // optional. | |
'view' => 'unlisted', // make video unlisted | |
'download' => false, // prevent downloads | |
); | |
); | |
$result = $api->upload_pull($url, $params); | |
var_dump($result['response']); | |
# Example 3 - Check the connection | |
var_dump($api->is_connected); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment