【问题标题】:Basic PHP Vimeo Advanced API Call基本 PHP Vimeo 高级 API 调用
【发布时间】:2014-04-08 06:20:27
【问题描述】:

这是一个自我问答。

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

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

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

【问题讨论】:

    标签: php authentication vimeo-api


    【解决方案1】:
    // 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
        }
    

    【讨论】:

    • 嗨,$token_secret 怎么样?
    【解决方案2】:

    访问https://github.com/leandrocfe/PHPVimeoAPI_List_Private_Video

    列出来自 Vimeo 的私人视频 |访问私人视频

    1. 修改config.json info vimeo账号;
    2. 访问 video.php 和 添加 vimeo_video_id 获取参数。前任: 本地主机/vimeo/video.php?id=123123123

      <?php
      
      //utf-8
      header('Content-Type: text/html; charset=utf-8');
      
      //lib vimeo
      use Vimeo\Vimeo;
      
      //métodos de inicialização
      $config = require(__DIR__ . '/init.php');
      
      //vimeo video id
      @$id = $_GET["id"];
      
      //isset get
      if(isset($id)){
      
          // vimeo class send config.json paramns
          $lib = new Vimeo($config['client_id'], $config['client_secret'], $config['access_token']);
      
          //get data vimeo video
          $me = $lib->request("/me/videos/$id");
      
          //iframe vídeo
          $embed = $me["body"]["embed"]["html"];
      
          //edit video size
          $default_size = 'width="'.$me["body"]["width"].'" height="'.$me["body"]["height"].'"';
          $new_size = 'width="420" height="220"';
      
          $embed = str_replace($default_size, $new_size, $embed);
      
          //autoplay
          $embed = str_replace('player_id=0', 'player_id=0&autoplay=1', $embed);
      
      }else{
      
          echo("Not find get id video");
      }
      ?>
      <!DOCTYPE html>
      <html>
          <head>
              <title>Vimeo Vídeo</title>
          </head>
          <body>
              <div><?php echo $embed ?></div>
              <div>
                  <p><b>Name: </b><?php print_r($me["body"]["name"]); ?></p>
                  <p><b>Description: </b><?php print_r($me["body"]["description"]); ?></p>
                  <p><b>Link: </b><?php print_r($me["body"]["link"]); ?></p>
                  <p><b>Likes: </b><?php print_r($me["body"]["embed"]["buttons"]["like"]); ?></p>
                  <p><b>Data Created: </b><?php print_r($me["body"]["created_time"]); ?></p>
                  <p><b>Data Modified: </b><?php print_r($me["body"]["modified_time"]); ?></p>
                  <p><b>Images: </b>
                      <?php print_r($me["body"]["pictures"]["uri"]); ?> |
                      <?php print_r($me["body"]["pictures"]["sizes"][0]["link"]); ?> |
                      <?php print_r($me["body"]["pictures"]["sizes"][1]["link"]); ?> |
                      <?php print_r($me["body"]["pictures"]["sizes"][2]["link"]); ?> |
                      <?php print_r($me["body"]["pictures"]["sizes"][3]["link"]); ?> |
                      <?php print_r($me["body"]["pictures"]["sizes"][4]["link"]); ?> |
                      <?php print_r($me["body"]["pictures"]["sizes"][5]["link"]); ?>
                      </p>
              </div>
              <div><?php //print_r($me); //use for show all options ?></div>
          </body>
      </html>
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多