I have a new project where my client is requesting to display the latest video from a specific Vimeo Portfolio. I already have a script that can fetch the latest video from the entire account using JavaScript as shown below:
http://codepen.io/buschschwick/pen/pgrmvg
var vimeoUserName = 'yellowboxfilms';
// Tell Vimeo what function to call
var videoCallback = 'latestVideo';
var oEmbedCallback = 'embedVideo';
// Set up the URLs
var videosUrl = 'http://vimeo.com/api/v2/' + vimeoUserName + '/videos.json?callback=' + videoCallback;
var oEmbedUrl = 'http://vimeo.com/api/oembed.json';
// This function puts the video on the page
function embedVideo(video) {
videoEmbedCode = video.html;
document.getElementById('embed').innerHTML = unescape(video.html);
}
// This function uses oEmbed to get the last clip
function latestVideo(videos) {
var videoUrl = videos[0].url;
// Get the oEmbed stuff
loadScript(oEmbedUrl + '?url=' + encodeURIComponent(videoUrl) + '&callback=' + oEmbedCallback);
}
// This function loads the data from Vimeo
function loadScript(url) {
var js = document.createElement('script');
js.setAttribute('type', 'text/javascript');
js.setAttribute('src', url);
document.getElementsByTagName('head').item(0).appendChild(js);
}
// Call our init function when the page loads
window.onload = function() {
loadScript(videosUrl);
};
However, I now need to fetch the latest video from a particular portfolio. I came across the API Call for this, but unfortunately, I encountered an authorization error.
http://codepen.io/buschschwick/pen/jWLoWb
var latestVideo = function() {
var vimeoAPI = 'https://api.vimeo.com/users/414104/portfolios';
$.getJSON(vimeoAPI).done(function(data) {
console.log(data);
})
};
latestVideo();
I suspect that an oAuth token is needed, but my attempts to figure out how to pass it have been futile. The Vimeo API Documentation hasn't been very clear either. Any advice or assistance on this matter would be greatly appreciated. Thank you!