myYoutubeREST is a Java RESTful practice implementation built in open source RESTful Web Services framework Jersey. Youtube Data Api v3 has been used to build the implementation. Upon entering a keyword and no of return values, implementation returns a defined no of Youtube videos serialized as JSON objects. Any web browser or REST Client e.g. Chrome Advanced REST Client could be used for it. This implementation is built in Linux environment.
At this moment this Implementation creates an endpoint to search desired no of youtube videos with a search query parameter and return videos as useful JSON objects. I am working towards creating my interactive practice application where along with returning the response with respect to the the passed parameters, endpoint will also make some suggestions which may appear useful and worth exploring to the user.
I am exploring Youtube Data and Analytics API for creating such an application which will drive the user’s probably interactions with the application state.
- This implementation creates Web Application Archive (.war) file and deploys the same in Glassfish container which can be downloaded from the link.
- It assumes that the user has a native installation of Gradle or a Wrapper pattern may also be used.
Clone the GitHub Repository
$ git clone https://github.com/sarkarchandan/myYoutubeREST
$ cd myYoutubeREST
- Go to Google Developers Console and create a new Project and right after creating new Project generate oAuth Client ID and oAuth Client Secret for your Project.
- Go to oAuth 2.0 Playground and use the oAuth Client ID and oAuth Client Secret to generate a Refresh Token for your Project which will be useful for oAuth 2.0 authenticated API Call to You tube Data Api.
- A comprehensive guide on how to generate the credentials can be found here .
- This implementation has been built using IntelliJ Idea but any IDE of user’s choice e.g. Eclipse can be used to import the project. Execute the corresponding gradle plug in to build the project workspace before importing.
$ gradle idea
OR
$ gradle eclipse
- Enter the Client ID and Client Secret to and generated Refresh Token for the registered project with Google Developer Console in the respective static fields of the YoutubeEngine class of the package de.uniba.myREST.engine
- Make sure that glassfish server container is running.
- Build the archive and deploy to the Container.
$ gradle build
$ gradle deploy
Open the web browser or Chrome Advanced REST Client and enter the URI with query string such as: http://localhost:8080/youtubeVideos/search?searchQuery=Nexus&noOfResources=5
{
"videoChannelId": "UCBJycsmduvYEL83R_U4JriQ"
"videoChannelTitle": "Marques Brownlee"
"videoDescription": "2016 Nexus Sailfish and Marlin are coming soon! AndroidPolice Exclusives: http://www.androidpolice.com/topics/news/exclusive/ Nexus Launcher apk: ..."
"videoETag": ""I_8xdZu766_FSaexEaDXTIfEWc0/DhC5bp2UFch0b-B9FlOrhW54Dwo""
"videoId": "C2p5aREEWvk"
"videoPublishedAt": "2016-08-10T21:19:27.000Z"
"videoThumbnailURI": "https://i.ytimg.com/vi/C2p5aREEWvk/default.jpg"
"videoTitle": "2016 Nexus Hype!"
"videoURI": "https://www.youtube.com/watch?v=C2p5aREEWvk"
}
At this point YoutubeEngine class expects the credentials to be entered directly to the class body. I am working to come up with a better method for that. noOfResources field is lacking validation as of now. I am working to add validation for it. I am open to any suggestions or comments.