【发布时间】:2016-06-27 17:39:30
【问题描述】:
背景: Vimeo PRO 帐户(视频所有者) 公共和私人视频 只能嵌入到我的域中
目标: 我只是想传入一个 VIDEO ID,然后返回一个 JSON 数据转储响应。(所以我可以在可嵌入的 iframe/播放器中使用它。但也能够显示视频中的描述,以及视频下载链接...这一切似乎都在 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"}
不确定我做错了什么?视频链接: https://vimeo.com/171811266
- 我相信我将此视频设置为 PUBLIC 以进行测试..etc
由于我无法使用这种方法.. 我继续尝试使用“官方图书馆”:
https://github.com/vimeo/vimeo.php
但是..恕我直言,它没有任何开箱即用的“工作示例”..
这是我目前尝试过的:
*我不清楚为什么我需要对“我”拥有的 Vimeo 帐户“我”拥有的视频进行“身份验证”......并且只能在“我”拥有的域上显示?
-
我不清楚为什么我需要将用户发送到 Vimeo 网站以“接受/批准”任何事情?然后将它们重定向回......到哪里?存放视频的页面?
//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 库? (此时文件和随机行太多,我无法理解我需要什么)
我不需要上传任何内容.. 我只需要/想要传递一个视频 ID 并取回该视频的 JSON 数据列表..(不需要用户信息...不需要上传..不要需要删除)
任何人都可以指导我或给我一些关于我做错了什么的方向吗?以及如何纠正?
谢谢
================================================ =========================== 更新:“什么对我有用!”
使用官方图书馆.. 自述文件“示例”对我不起作用(正如我发布的那样)..
但是.. 这确实对我有用:(再次,使用官方库)
<?
//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>';
?>
【问题讨论】: