gpt4 book ai didi

php - 基本 PHP Vimeo 高级 API 调用

转载 作者:可可西里 更新时间:2023-11-01 12:35:33 26 4
gpt4 key购买 nike

这是 self 问答。

我经常四处寻找有关使用 Vimeo API 的帮助,但总是发现入门级示例和文档很难理解。所以我写了这个问答来帮助那些需要它的人。那么问题来了:

如何使用 Vimeo PHP“高级 API”获取我的所有 Vimeo 视频?

关键是“我的”视频。这对于构建希望与自己的 Vimeo 帐户同步的网站的人很有用。 Vimeo 示例都旨在允许第 3 方用户根据需要进行身份验证。这是一次性静态身份验证示例。

最佳答案

// Include the Vimeo API file. Download from here: https://github.com/vimeo/vimeo-php-lib
require_once('vimeo.php');

/*
* Helper Function to Handle Vimeo Authentication
*/
function authenticate_vimeo(){
// Settings below.
// You'll need to set these to your account's as show here: // Get from https://developer.vimeo.com/apps/new

$vimeo_id = 'user12345'; // Get from https://vimeo.com/settings, must be in the form of user123456
$consumer_key = '1234567';
$consumer_secret = '1234567';
$token = '1234567';
$token_secret = '1234567';

// Do an authentication call
$vimeo = new phpVimeo($consumer_key, $consumer_secret);
$vimeo->setToken($token, $token_secret);
$vimeo->user_id = $vimeo_id;

return $vimeo;
}

/*
* This is how you make a call to the Vimeo API
*/
// Authenticate Vimeo
$vimeo = authenticate_vimeo();

// Try to access the API
try {
$args = array(
'full_response' => true,
'user_id' => $vimeo->user_id, // This limits the request to the one user's videos
'per_page' => 50, // 50 is the max per page, use "page" parameter for more pages
);
$results = $vimeo->call('vimeo.videos.getUploaded', $args); // List of methods here: https://developer.vimeo.com/apis/advanced/methods
}
catch (VimeoAPIException $e) {
$error = "Encountered an API error -- code {$e->getCode()} - {$e->getMessage()}";
}

// Do something with error or results
if( isset($error) ) {
print_r($error);
} else {
print_r($results); // This will be a gigantic PHP object of all videos and meta data
}

关于php - 基本 PHP Vimeo 高级 API 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22929081/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com