【发布时间】:2016-10-27 15:13:54
【问题描述】:
我有一个 Vimeo PRO 帐户。 我已上传受保护的视频。 视频也设置为只能嵌入到我的域中(在视频设置中设置)
我 - 不 - 掌握如何使用他们的例子(对不起,对我来说,这些例子不包括对我来说真正的工作样本,..或者至少如何实现它们以理解..所以我希望得到一些帮助)
不清楚所有 OAuth2、Oembed... 身份验证的东西.. 我相信这是我的问题所在。
我正在关注这个 gitHub 示例:
https://github.com/vimeo/vimeo-api-examples/blob/master/oembed/php-example.php
(看起来很老?)
我希望在传递 ID 时为视频返回 JSON 数据。
我曾经/现在认为我需要“验证”才能获得响应/返回数据?
这最好在 CURL 标头中完成吗?
有人可以指导我更多吗? (不应该这么难!)哈哈..
这是我的代码:
$video_endpoint = 'https://api.vimeo.com/videos/';
$video_url = '171811266';
//JSON url
//$json_url = $video_endpoint . '.json?url=' . rawurlencode($video_url);
//this fixes the cURL approach
$json_url = $video_endpoint . rawurlencode($video_url);
// Curl helper function
function curl_get($url) {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
//curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization : bearer xxxxxx'));
$return = curl_exec($curl);
curl_close($curl);
return $return;
}
$vimeoJSON = json_decode((curl_get($json_url)));
var_dump($vimeoJSON);
我得到了这样的回应:
object(stdClass)#1 (1) { ["error"]=> string(52) "You must provide a valid authenticated access token." }
问题是:
1.) 这甚至是一种有效的方法吗? (假设我只需要在 CURL 标头中添加几行代码以在收到响应之前发送我的身份验证?)
2.) 如何更新我的 CURL sn-p 以使用 VIEMO 身份验证?
我尽量保持简洁/简单(对于 JSON 调用/返回部分)..
感谢任何指导。
谢谢
更新:
此代码不起作用:
$access_token = 'xxx';
$video_endpoint = 'https://api.vimeo.com/videos/';
$video_url = '171811266';
$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;
}
我要使用的视频位于这里:
https://vimeo.com/171811266/5822169b48
这是一个私人视频。 (不确定你能看到它)..
当我使用上面发布的代码的最新版本时.. 我得到这个响应:
{"error":"The requested video could not be found"}
这是因为它是私人视频吗?
(实际上我只是将视频设置为任何人都可以观看..我仍然得到相同的错误/响应)(未找到)
如果是这样.. 使用我的视频的解决方法是什么.. 设置为私有...但仍然在我的站点/域上使用它们?
================================================ ==============================
最终更新:
尝试使用自述文件示例中的代码: https://github.com/vimeo/vimeo.php
尝试使用(未成功)LIB @Dashron 也指出了我。我什至似乎无法从 GIT 页面获得基础知识:
代码:
//project vars
$client_id = 'xxxx';
$client_secret = 'xxx';
$access_token = 'xxx';
$redirect_uri = 'http://domain.com/file.php'; //where do I redirect them back to? the page where I have the embeded video at?
// 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';
require("Vimeo/autoload.php");
$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']);
我收到此错误消息:
Parse error: syntax error, unexpected Fatal error: Class 'Vimeo\Vimeo' not found in /usr/www/users/aaemorg/aaem.org/video/vimeo_lib.php
似乎它没有创建实例化我的 $lib 对象/类??
(我知道我在高级 PHP 类/代码方面并不出色......但这很难为我拥有的视频获得 JSON 响应以(再次)嵌入到我拥有的网站上)
任何方向将不胜感激?
================================================ ========================
更新:“什么对我有用”..
我很欣赏“官方”库的链接。但自述文件示例对我不起作用...
为了让其他可能对 Vimeo API 不熟悉的人也能轻松搞定。这里有一个快速而肮脏的简单代码示例,可帮助您启动和运行:
<?
//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>';
?>
【问题讨论】:
-
@Cfreak - 感谢您的协助! (我对此感到震惊!)