Asked 7 years ago
28 Jan 2017
Views 1834
lain

lain posted

Youtube api in java

how to use Youtube api in java
Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00

1. download Google API Client Library for Java

2. Append jar to your project
in Eclipse, set the "Source attachment" for each class jar file to its corresponding "-sources" jar file.
so extract zip and attach following jar to Application environment

data-client-1.0.jar
gdata-youtube-2.0.jar
gdata-core-1.0.jar
gdata-media-1.0.jar

3. write some code

suppose following code is for list of video uploaded by user
   
List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube.readonly");
        try {
            Credential credential = Auth.authorize(scopes, "myuploads");
            youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential).setApplicationName(
                    "youtube-cmdline-myuploads-sample").build();
            YouTube.Channels.List channelRequest = youtube.channels().list("contentDetails");
            channelRequest.setMine(true);
            channelRequest.setFields("items/contentDetails,nextPageToken,pageInfo");
            ChannelListResponse channelResult = channelRequest.execute();\
            List<Channel> channelsList = channelResult.getItems();
} catch (Throwable t) {
            t.printStackTrace();
        }

more sample @
Github , @google-developer-doc
Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00

if you are using for Android than use the Google Play Services library for the best performance and experience.
Google Play Services :: https://developer.android.com/google/play-services/index.html
other useful lib for Google api
Google Collections Library :: http://code.google.com/p/google-collections/
JavaMail API :: http://java.sun.com/products/javamail
Post Answer