Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
601 views
in Technique[技术] by (71.8m points)

authentication - Basic PHP Vimeo Advanced API Call

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
// 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
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...