Last active
December 29, 2015 02:49
-
-
Save MeoMix/7603096 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var YouTubeDataAPI = Backbone.Model.extend({ | |
sendV2ApiRequest: function(options) { | |
return $.ajax({ | |
url: options.url, | |
data: $.extend({}, options.data, { | |
// The v parameter specifies the version of the API that YouTube should use to handle the API request. | |
v: 2, | |
// The alt parameter specifies the format of the feed to be returned. | |
alt: 'json', | |
// If you want YouTube to reject API requests that contain invalid parameters, set the strict parameter value to true | |
strict: true | |
}), | |
// A developer key uniquely identifies a product that is submitting an API request. | |
// https://developers.google.com/youtube/2.0/developers_guide_protocol#Developer_Key | |
headers: { | |
'X-GData-Key': 'key=[KEY]' | |
}, | |
success: function() { | |
if (options.success) { | |
options.success(arguments[0]); | |
} | |
}, | |
error: function(error) { | |
// Manually aborted events don't need to be reported on | |
if (error.statusText !== 'abort') { | |
console.error(error); | |
} | |
if (options.error) { | |
options.error(arguments[0]); | |
} | |
} | |
}); | |
}, | |
getPlaylistTitle: function (playlistId, callback) { | |
return this.sendV2ApiRequest({ | |
url: 'https://gdata.youtube.com/feeds/api/playlists/' + playlistId, | |
data: { | |
fields: 'title' | |
}, | |
success: function (result) { | |
if (callback) { | |
callback(result.feed.title.$t); | |
} | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment