2016-06-24 45 views
1

我有一個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>'; 


?> 
+1

@Cfreak - 感謝您的幫助! (釉面我就在那!) – whispers

回答

0

您提供的鏈接非常非常舊。它實際上是不同API的一部分,不再相關。

圖書館,你應該使用位於:https://github.com/vimeo/vimeo.php在自述許多例子,例子目錄!

+0

感謝您的答覆..因爲我不可能獲得捲曲的工作方式(不幸的是..我只是想要一個簡單的JSON回用,因爲我認爲合適).. 我會嘗試使用您鏈接的庫。它看起來像很多額外的東西..只是爲了獲得簡單的JSON回報? 你能向我解釋爲什麼,如果這是我的視頻..我想對我的域顯示它們(在隱私視頻設置也使用/嵌入)...爲什麼我需要這個認證的東西? 我不完全理解爲什麼我需要發送用戶到vimeo頁面/站點以便用戶批准/接受任何內容? – whispers

+0

我只想在我自己的網站上嵌入私人視頻? 我希望得到一個JSON回報(使用.PHP),所以我顯示視頻本身(iframe或其他)...顯示description..and下載的視頻都在我的網站(又影片和網站都是由我擁有) – whispers

+0

我使用您提供的鏈接嘗試失敗後更新了原始帖子。錯誤在$網址線路輸出.. 如何獲取視頻ID簡單的JSON響應任何意見/方向? (也許clrarify爲什麼我需要做的所有視頻這個東西權威性「我」自己..只有被嵌入在網站上的「我」自己呢? 謝謝! – whispers