Vimeo API 帮助(cURL 或库)?
Vimeo API help (cURL or Library)?
背景:
Vimeo PRO 帐户(视频所有者)
public 和私人视频
只能嵌入我的域
目标:
我只是想传入一个视频 ID,并返回一个 JSON 数据转储响应。(所以我可以在可嵌入的 iframe/player 中使用它。但也能够显示来自视频,以及视频下载 links...这一切似乎都可以在 JSON 返回的数据中找到)
我尝试了一种简单的 cURL 方法..
//project vars
$client_id = 'xxx';
$client_secret = 'xxx';
$access_token = 'xxx';
$video_endpoint = 'https://api.vimeo.com/videos/';
$video_url = '171811266';
//$video_url = '171811266/5822169b48';
$json_url = $video_endpoint . '.json?url=' . rawurlencode($video_url);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $json_url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"authorization: Bearer ".$access_token
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
}else {
echo $response;
}
虽然我 - 认为 - 我在正确的轨道上(即使它是一种老方法)..
我收到这个错误:
{"error":"The requested video could not be found"}
不确定我做错了什么?视频 link:
https://vimeo.com/171811266
- 我相信我将此视频设置为 PUBLIC 用于测试..等等
因为我无法使用这种方法..我继续尝试使用 'official library':
https://github.com/vimeo/vimeo.php
但是.. 恕我直言,它没有开箱即用的 'working examples'..
这是我到目前为止尝试过的方法:
*我不清楚为什么我需要 'authenticate' 视频 "I" 拥有..在 Vimeo 帐户 "I" 拥有..并且只能显示在域 "I"自己的?
我不清楚为什么我需要将用户发送到 Vimeo 站点以 'accept/approve' 任何东西?然后将它们重定向回...到哪里?视频所在的页面?
//project vars
$client_id = 'xxxx';
$client_secret = 'xxx';
$access_token = 'xxx';
$redirect_uri = 'http://www.domain.com/file.php'; //what URL should this be? The .php page that has the embedded player on it?
// scope is an array of permissions your token needs to access. You can read more at https://developer.vimeo.com/api/authentication#scopes
$scopes = Array('public', 'private');
$state = 'Ldhg0478y'; //randomly made up state variable/value
require("Vimeo/autoload.php");
// instantiate a new instance of Vimeo class/object
$lib = new \Vimeo\Vimeo($client_id, $client_secret);
// build a link to Vimeo so your users can authorize your app. //whatever that means and is for?
$url = $lib->buildAuthorizationEndpoint($redirect_uri, $scopes, $state);
// redirect_uri must be provided, and must match your configured uri
$token = $lib->accessToken(code, redirect_uri);
// usable access token
var_dump($token['body']['access_token']);
// accepted scopes
var_dump($token['body']['scope']);
// use the token
$lib->setToken($token['body']['access_token']);
$response = $lib->request('/me/videos', array('per_page' => 2), 'GET');
var_dump($response['body']);
我对上面的回复是:
Notice: Use of undefined constant code - assumed 'code' in /usr/www/users/domain_name.org/file_name.php on line 27
Notice: Use of undefined constant redirect_uri - assumed 'redirect_uri' in /usr/www/users/domain_name.org/file_name.php on line 27
Notice: Undefined index: access_token in /usr/www/users/domain_name.org/file_name.php on line 30
NULL
Notice: Undefined index: scope in /usr/www/users/domain_name.org/file_name.php on line 33
NULL
Notice: Undefined index: access_token in /usr/www/users/domain_name.org/file_name.php on line 36
array(1) { ["error"]=> string(52) "You must provide a valid authenticated access token." }
如果我能让 cURL 版本工作,我想我会感觉更舒服并且有更多的控制权(我想?)?而不是尝试使用这个 Vimeo 库? (目前有太多文件和随机行对我来说意义不大,无法理解我需要什么)
我不需要上传任何东西..我只需要 to/want 传递视频 ID 并获取该视频的 JSON 数据列表..(不需要用户信息.. .不需要上传..不需要删除)
任何人都可以指导我或指导我做错了什么吗?以及如何纠正它?
谢谢
============================================= ============================
更新:"What worked for me!"
使用官方图书馆..自述文件 'example' 对我不起作用(正如我发布的那样)..
但是..这对我有用:(再次使用官方库)
<?
//include offifial library
require("Vimeo/autoload.php");
$client_id = 'xxx';
$client_secret = 'xxx';
$access_token = 'xxx';
$video_id = 'xxx';
$lib = new Vimeo\Vimeo($client_id, $client_secret, $access_token);
$video_response = $lib->request('/videos/'.$video_id);
//dont really need this, but included in case there is some data you need to display
$token_response = $lib->clientCredentials();
//example of parsing out specific data from the array returned
//name/title
echo $video_response['body']['name'] . '<br><br>';
?>
你从哪里得到 .json?url= 部分?您的请求 url 应该只是
$json_url = $video_endpoint . rawurlencode($video_url);
您的代码适用于该更改。
参考:https://developer.vimeo.com/api/endpoints/videos#/{video_id}
背景: Vimeo PRO 帐户(视频所有者) public 和私人视频 只能嵌入我的域
目标: 我只是想传入一个视频 ID,并返回一个 JSON 数据转储响应。(所以我可以在可嵌入的 iframe/player 中使用它。但也能够显示来自视频,以及视频下载 links...这一切似乎都可以在 JSON 返回的数据中找到)
我尝试了一种简单的 cURL 方法..
//project vars
$client_id = 'xxx';
$client_secret = 'xxx';
$access_token = 'xxx';
$video_endpoint = 'https://api.vimeo.com/videos/';
$video_url = '171811266';
//$video_url = '171811266/5822169b48';
$json_url = $video_endpoint . '.json?url=' . rawurlencode($video_url);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $json_url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"authorization: Bearer ".$access_token
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
}else {
echo $response;
}
虽然我 - 认为 - 我在正确的轨道上(即使它是一种老方法)..
我收到这个错误:
{"error":"The requested video could not be found"}
不确定我做错了什么?视频 link: https://vimeo.com/171811266
- 我相信我将此视频设置为 PUBLIC 用于测试..等等
因为我无法使用这种方法..我继续尝试使用 'official library':
https://github.com/vimeo/vimeo.php
但是.. 恕我直言,它没有开箱即用的 'working examples'..
这是我到目前为止尝试过的方法:
*我不清楚为什么我需要 'authenticate' 视频 "I" 拥有..在 Vimeo 帐户 "I" 拥有..并且只能显示在域 "I"自己的?
我不清楚为什么我需要将用户发送到 Vimeo 站点以 'accept/approve' 任何东西?然后将它们重定向回...到哪里?视频所在的页面?
//project vars $client_id = 'xxxx'; $client_secret = 'xxx'; $access_token = 'xxx'; $redirect_uri = 'http://www.domain.com/file.php'; //what URL should this be? The .php page that has the embedded player on it? // scope is an array of permissions your token needs to access. You can read more at https://developer.vimeo.com/api/authentication#scopes $scopes = Array('public', 'private'); $state = 'Ldhg0478y'; //randomly made up state variable/value require("Vimeo/autoload.php"); // instantiate a new instance of Vimeo class/object $lib = new \Vimeo\Vimeo($client_id, $client_secret); // build a link to Vimeo so your users can authorize your app. //whatever that means and is for? $url = $lib->buildAuthorizationEndpoint($redirect_uri, $scopes, $state); // redirect_uri must be provided, and must match your configured uri $token = $lib->accessToken(code, redirect_uri); // usable access token var_dump($token['body']['access_token']); // accepted scopes var_dump($token['body']['scope']); // use the token $lib->setToken($token['body']['access_token']); $response = $lib->request('/me/videos', array('per_page' => 2), 'GET'); var_dump($response['body']);
我对上面的回复是:
Notice: Use of undefined constant code - assumed 'code' in /usr/www/users/domain_name.org/file_name.php on line 27
Notice: Use of undefined constant redirect_uri - assumed 'redirect_uri' in /usr/www/users/domain_name.org/file_name.php on line 27
Notice: Undefined index: access_token in /usr/www/users/domain_name.org/file_name.php on line 30
NULL
Notice: Undefined index: scope in /usr/www/users/domain_name.org/file_name.php on line 33
NULL
Notice: Undefined index: access_token in /usr/www/users/domain_name.org/file_name.php on line 36
array(1) { ["error"]=> string(52) "You must provide a valid authenticated access token." }
如果我能让 cURL 版本工作,我想我会感觉更舒服并且有更多的控制权(我想?)?而不是尝试使用这个 Vimeo 库? (目前有太多文件和随机行对我来说意义不大,无法理解我需要什么)
我不需要上传任何东西..我只需要 to/want 传递视频 ID 并获取该视频的 JSON 数据列表..(不需要用户信息.. .不需要上传..不需要删除)
任何人都可以指导我或指导我做错了什么吗?以及如何纠正它?
谢谢
============================================= ============================ 更新:"What worked for me!"
使用官方图书馆..自述文件 'example' 对我不起作用(正如我发布的那样)..
但是..这对我有用:(再次使用官方库)
<?
//include offifial library
require("Vimeo/autoload.php");
$client_id = 'xxx';
$client_secret = 'xxx';
$access_token = 'xxx';
$video_id = 'xxx';
$lib = new Vimeo\Vimeo($client_id, $client_secret, $access_token);
$video_response = $lib->request('/videos/'.$video_id);
//dont really need this, but included in case there is some data you need to display
$token_response = $lib->clientCredentials();
//example of parsing out specific data from the array returned
//name/title
echo $video_response['body']['name'] . '<br><br>';
?>
你从哪里得到 .json?url= 部分?您的请求 url 应该只是
$json_url = $video_endpoint . rawurlencode($video_url);
您的代码适用于该更改。
参考:https://developer.vimeo.com/api/endpoints/videos#/{video_id}