基本的PHP Vimeo高级API调用

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了基本的PHP Vimeo高级API调用脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
这是一个自我Q& A.

我经常四处寻找有关使用vimeo API的帮助,并且总是发现入门级示例和文档很难遵循.所以我把这个Q& A写成了那些需要它的人的帮助.所以这是一个问题:

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

关键是“我的”视频.这对于构建他们想要与他们自己的Vimeo帐户同步的站点的人来说非常有用. Vimeo示例都旨在允许第三方用户根据需要进行身份验证.这是一次性静态身份验证示例.

// 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调用全部内容,希望文章能够帮你解决基本的PHP Vimeo高级API调用所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。