我正在尝试使用Vimeo API获取视频mp4 URL,其官方文档说要向https://api.vimeo.com/videos/[video_id]发出经过身份验证的GET请求 以下是我在github上找到的代码,但未返回任何内容。
$url = "https://api.vimeo.com/videos/$videoid";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36");
$result = curl_exec($ch);
有人可以建议我如何向Vimeo API发出经过身份验证的GET请求吗? 我有Vimeo密钥和访问令牌。 谢谢。
答案 0 :(得分:1)
由于您说您已经拥有令牌,因此可以尝试使用获得的令牌进行此代码。
确保还要输入您的视频ID。获取您的视频ID。单击视频以在浏览器中打开。获取您的vimeo帐户的视频ID 例如在浏览器网址上
https://vimeo.com/ 12083674
<?php
//$your_video_id='12083674';
$your_video_id='your video id goes here';
$access_token='your access token goes here';
$clink = "https://api.vimeo.com/videos/$your_video_id";
$curl=curl_init();
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_URL,$clink);
curl_setopt($curl,CURLOPT_CUSTOMREQUEST,'GET');
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
"Authorization: Bearer $access_token")
);
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,0);
$out = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
var_dump($out);
if($status==200){
echo "video found<br>";
}else{
echo "There is an issue. Try Again..<br>";
}