Vimeo API 2016如何显示用户视频列表

时间:2016-06-07 09:25:56

标签: php vimeo vimeo-api

我无法找到使用Vimeo API的简化教程我知道我需要包含vimeo.php和以下

include 'vimeo.php';

$vimeo = new phpVimeo('Client Identifier', 'Client Secrets');
$videos = $vimeo->call('vimeo.videos.getUploaded', array('user_id' => "user1877648"));

print_r($videos);

我已经从访问身份验证中复制并粘贴了我使用过的字段,以防出现问题,我还读到,对API的简单调用不需要访问令牌?

关于如何从特定用户获取链接到vimeo url的vimeo thumb列表,我真的可以做一些指示吗?我使用的是较旧的代码,直到最近才运行良好。

2 个答案:

答案 0 :(得分:3)

Dashron指出了所有正确的地方,找到了你想要做的事情所需的文件。

但是,这是一个如何做的例子。

您需要下载/克隆Vimeo PHP库(可在此处找到:https://github.com/vimeo/vimeo.php)。

然后转到Vimeo并创建一个应用程序,以便您可以获取客户端ID和客户端密钥(https://developer.vimeo.com/api/start)。

现在您拥有客户端ID,客户端密码和vimeo库,您可以创建一个简单的脚本来加载来自特定用户的所有视频。这是一个例子:

<?php

// include the autoload file from the vimeo php library that was downloaded
include __DIR__ . '/vimeo/autoload.php';

// The client id and client secret needed to use the vimeo API
$clientId = "";
$clientSecret = "";

// when getting an auth token we need to provide the scope
// all possible scopes can be found here https://developer.vimeo.com/api/authentication#supported-scopes
$scope = "public";

// The id of the user
$userId = "alexbohs";

// initialize the vimeo library
$lib = new \Vimeo\Vimeo($clientId, $clientSecret);

// request an auth token (needed for all requests to the Vimeo API)
$token = $lib->clientCredentials($scope);

// set the token
$lib->setToken($token['body']['access_token']);

// request all of a user's videos, 50 per page
// a complete list of all endpoints can be found here https://developer.vimeo.com/api/endpoints
$videos = $lib->request("/users/$userId/videos", ['per_page' => 50]);

// loop through each video from the user
foreach($videos['body']['data'] as $video) {

    // get the link to the video
    $link = $video['link'];

    // get the largest picture "thumb"
    $pictures = $video['pictures']['sizes'];
    $largestPicture = $pictures[count($pictures) - 1]['link'];
}

请注意,vimeo API会返回视频的“页面”。因此,如果用户每页有超过50个视频,则需要使用“页面”参数指定页码,对每个页面执行请求(将['per_page' => 50]更改为['per_page' => 50, 'page' => #]

答案 1 :(得分:0)

这是旧的高级API。它已被弃用。

新的PHP库位于:https://github.com/vimeo/vimeo.php

新的API文档位于:https://developer.vimeo.com/api

检索所有视频的端点是https://api.vimeo.com/me/videoshttps://developer.vimeo.com/api/endpoints/me#/videos