java - Retrieving details from a YouTube video given the URL -
for example, given link https://www.youtube.com/watch?v=hl-zzrqqose video installing java jdk.
using java , youtube-api, how can information such length, title, , views?
i looked , found https://developers.google.com/youtube/2.0/developers_guide_protocol_video_entries it's outdated , i'm not sure how use it.
forgive ignorance i'm new java. thanks.
you can use videos:list , specify video id retrieve video information specific video. example:
youtube youtube = new youtube.builder(new nethttptransport(), new jacksonfactory(), new httprequestinitializer() { public void initialize(httprequest request) throws ioexception { } }).setapplicationname("video-test").build(); final string videoid = "hl-zzrqqose"; youtube.videos.list videorequest = youtube.videos().list("snippet,statistics,contentdetails"); videorequest.setid(videoid); videorequest.setkey("{your-api-key}"); videolistresponse listresponse = videorequest.execute(); list<video> videolist = listresponse.getitems(); video targetvideo = videolist.iterator().next();
targetvideo
hold information related video. can information such title, view count , duration object:
targetvideo.getsnippet().gettitle(); targetvideo.getstatistics().getviewcount(); targetvideo.getcontentdetails().getduration();
the following imports required:
import com.google.api.client.http.httprequest; import com.google.api.client.http.httprequestinitializer; import com.google.api.client.http.javanet.nethttptransport; import com.google.api.client.json.jackson2.jacksonfactory; import com.google.api.services.youtube.youtube; import com.google.api.services.youtube.model.video; import com.google.api.services.youtube.model.videolistresponse; import java.io.ioexception; import java.util.list;
Comments
Post a Comment