【问题标题】:"invalid_token" response using Vimeo's "brand new API"使用 Vimeo 的“全新 API”的“invalid_token”响应
【发布时间】:2014-05-03 14:27:45
【问题描述】:

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

【问题讨论】:

  • 您的问题中包含“/users/dashron”似乎很奇怪,而@Dashron 是回答的用户的名称......
  • 我认为他是从一开始就编写示例代码的人。

标签: php upload vimeo vimeo-api


【解决方案1】:

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

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

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

如果您没有大量需要转换的现有用户,您可以使用应用页面中的 OAuth 2 令牌,或使用 OAuth 2 authentication workflow 生成新用户

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

【讨论】:

  • 谢谢!意识到我还有更多需要学习。无论如何,我通过使用我的应用程序页面上 OAuth2 部分的访问令牌来获取新 API 的工作。我必须编辑 index.php 代码示例并提供访问令牌(如我上面的帖子中所述),否则它将无法工作。
  • 前进了半步。下一个问题是我在运行“upload.php”示例时收到“无法获取上传票证”。我使用与“index.php”示例相同的 id、秘密和令牌。通过 vimeo 扫描.php 代码,请求上传票证的状态响应似乎不是“200”而是“201”。更新 vimeo.php 以接受“201”响应允许上传视频。
  • 试试新的库,我们昨晚修复了这个错误。
  • 太棒了!谢谢!会的。
猜你喜欢
  • 1970-01-01
  • 2017-04-05
  • 1970-01-01
  • 2018-08-11
  • 1970-01-01
  • 2019-09-21
  • 1970-01-01
  • 2014-01-30
  • 1970-01-01
相关资源
最近更新 更多