我正在尝试创建一个使用 viemo api 搜索视频然后以 xml 格式输出的站点。我有一个好的开始,但现在我陷入了困境。用户输入正在发布,但萤火虫控制台上没有显示任何结果......
这是我用于 vimeo api 集成的 .php:
<?
include('connect.php');
$video_id= $_POST['text'];
$url = 'http://vimeo.com/api/rest/v2';
$url .= '?';
$url .= 'method=vimeo.videos.search&';
$url .= 'oauth_consumer_key='.$api_key2.'&';
$url .= 'per_page=10&';
$url .= 'query='.$video_id.'&';
$url .= 'sort=relevant&';
$url .= 'full_response=1';
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$curl_response = curl_exec($ch);
curl_close($ch);
$xmlObject = simplexml_load_string($curl_response);
$title= 'title';
$id = 'id';
$video_url = 'videosurl';
$thumbnails = 'thumbnail[1]';
$outputXML .= "";
$outputXML .= "<rsp>\n";
foreach($xmlObject->videos as $video) {
$videoTagBegin = "\t<video>\n";
$urlXML = "\t\t<videosurl>".$video->attributes()->$video_url."</videosurl>\n";
$titleXML = "\t\t<title>".$video->attributes()->$title."</title>\n";
$thumbXML = "\t\t<thumbnail>".$video->attributes()->$thumbnails."</thumbnail>\n";
$videoTagEnd = "\t</video>\n";
$outputXML .= $videoTagBegin.$titleXML.$thumbXML.$urlXML.$videoTagEnd;
}
$outputXML .= "</rsp>";
print $outputXML;
?>
任何帮助,将不胜感激。我完全被困住了。
如果它有帮助的话,这是我的 JS....
function closeDivs(e) {
e.preventDefault();
$('').empty();
};
$(document).ready(function() {
$('#searchbtn').bind('click' || 'enter',function(e) {
if ($.trim($('#searchBox').val()) !== '') {
$('#videos').empty();
closeDivs(e);
$('#videos').append('<img src="img/loading.gif" alt="loading" class="loading" />');
getEvents(e);
getVideos(e);
}
});
function getEvents(e) {
e.preventDefault();
var text = 'event_id='+$('#searchBox').val();
$.ajax({
url: 'getEvents.php',
dataType: 'xml',
type: 'POST',
data: text,
success: function(data) {
},
error: function(data) {
console.log('Error: ' + data);
}
})
};
function getVideos(e) {
e.preventDefault();
var text = 'video_id='+$('#searchBox').val();
$.ajax({
url: 'getVideos.php',
dataType: 'xml',
type: 'POST',
data: text,
success: function(data) {
},
error: function(data) {
console.log('Error: ' + data);
}
})
};
});