我已经开始运行 Github 上提供的 Vimeo 的 PHP 代码示例。我已经向 Vimeo 注册了一个应用程序来获取客户端 ID、客户端密码等,并且使用“旧”Vimeo API 和代码示例可以正常工作。
现在,使用新的 API 作为未来证明似乎是个好主意。但是,当运行基本的“index.php”示例时,我得到一个 invalid_token 响应,运行“upload.php”示例会给出响应“无法获取上传票证”。
我很确定我的客户端 ID、客户端密码和访问令牌是正确的,因为它适用于旧 API。
索引.php:
require_once('../vimeo.php');
$config = json_decode(file_get_contents('./config.json'), true);//<- Tokens are stored in a separate file
//$lib = new Vimeo($config['client_id'], $config['client_secret']);//<- I tried this first, but the response asked for an access token.
$lib = new Vimeo($config['client_id'], $config['client_secret'], $config['access_token']);
//$user = $lib->request('/users/dashron');
$user = $lib->request('/me');
print_r($user);
响应:“您必须提供有效的访问令牌”和“[Expires] => Tue, 30 Apr 2024 14”
上传.php:
$lib = new Vimeo($config['client_id'], $config['client_secret'], $config['access_token']);
$files = array("testvideo.mov");//<- Just a test file to try the code example
// Keep track of what we have uploaded.
$uploaded = array();
// Send the files to the upload script.
foreach ($files as $file_name) {
// Update progress.
print 'Uploading ' . $file_name . "\n";
try {
// Send this to the API library.
$uri = $lib->upload($file_name);
//rest of the code stripped out, but it's identical to the example
响应:“上传 testvideo.mov 上传 testvideo.mov 服务器报告错误:无法获得上传票证。上传了 0 个文件。”