我有一個Vimeo PRO帳戶。 我上傳了受保護的視頻。 影片也被設置爲只在我的領域嵌入(在視頻設置中設置)VIMEO(Pro)獲得JSON響應幫助(PHP/CURL)
我-not-掌握如何使用自己的例子(對不起,我的例子不包括實際的工作樣本對我來說, ..或至少如何實現他們理解..所以我希望能得到一些幫助)
不清楚所有的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代碼段以使用VIEMO身份驗證?
我試圖保持這種清潔/ SIMPLE,我可以(爲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 - 感謝您的幫助! (釉面我就在那!) – whispers