0

我已经开始运行 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 个文件。”

4

1 回答 1

0

访问令牌不会在新旧 API 之间传输,只会在您的客户端 ID 和客户端密码之间传输。

如果您有一堆需要转换为 API3 的预先保存的令牌,则有一个“交换令牌”端点。

您使用经过身份验证的 OAuth 1.0a 请求获取 /oauth/exchange,我们将返回访问令牌响应。

如果您没有大量需要转换的现有用户,您可以使用应用页面中的 OAuth 2 令牌,或使用OAuth 2 身份验证工作流程生成新用户

不过,它可能需要特殊权限,因此如果遇到问题,您应该通过https://vimeo.com/help/contact联系 Vimeo 。

于 2014-05-05T15:45:21.317 回答