基本PHP Vimeo的高级API调用 [英] Basic PHP Vimeo Advanced API Call
问题描述
这是一个自Q&安培; A
。我经常环顾四周,帮助上使用Vimeo的API,始终发现入门级的实例和文档很难跟上。所以我写了这个Q&放大器; A为帮助那些需要它。因此,这里的问题是:
如何使用PHP Vimeo的高级API来获得我的所有Vimeo的视频吗?
最关键的是我的视频。这是人们建立一个网站,他们希望用自己的Vimeo账户进行同步有用。 Vimeo的的例子都旨在允许第三方用户根据需要进行身份验证。这是一次性的静态验证的例子。
//包含了Vimeo的API文件。从这里下载:https://github.com/vimeo/vimeo-php-lib
require_once('vimeo.php');/ *
*辅助函数来处理Vimeo的身份验证
* /
功能authenticate_vimeo(){
//下面设置。
//你需要这些设置在这里对您的帐户作为显示:从https://developer.vimeo.com/apps/new //获取 $ vimeo_id ='user12345'; //从https://vimeo.com/settings获取,必须在user123456形式
$ CONSUMER_KEY ='1234567';
$ CONSUMER_SECRET ='1234567';
$令牌='1234567';
$ token_secret ='1234567'; //做一个验证电话
$ VIMEO =新phpVimeo($ CONSUMER_KEY,$ CONSUMER_SECRET);
$ vimeo-> setToken($令牌,$ token_secret);
$ vimeo-> USER_ID = $ vimeo_id; 返回$ VIMEO;
}/ *
*这是你如何让到Vimeo的API的调用
* /
// Vimeo的身份验证
$ VIMEO = authenticate_vimeo(); //尝试访问API
尝试{
的$ args =阵列(
full_response'=>真正,
'USER_ID => $ vimeo-> USER_ID,//这限制了请求向所述一个用户的视频
per_page'=>更多页面50,50 //每页最大,使用页参数
);
$结果= $ vimeo->调用('vimeo.videos.getUploaded',$参数); //这里的方法列表:https://developer.vimeo.com/apis/advanced/methods
}
赶上(VimeoAPIException $ E){
$错误=遇到一个API错误 - code {$ E-GT&;得到code()} - {$ E-GT&;的getMessage()};
} //做一些错误或结果
如果(使用isset($错误)){
的print_r($错误);
}其他{
的print_r($结果); //这将是所有视频和元数据的巨大PHP对象
}
This is a self Q&A.
I've often looked around for help on using the Vimeo API, and always found the entry level examples and documentation very difficult to follow. So I've written this Q&A as help to those that need it. So here is the question:
How do I use the Vimeo PHP "Advanced API" to get all of my Vimeo videos?
The key is "my" videos. This is useful for people building a site that they want to synch with their own Vimeo account. The Vimeo examples are all geared towards allowing a 3rd party user to authenticate as needed. This is a one time static authentication example.
// 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 Vimeo的高级API调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!