YouTube订阅渠道API

时间:2018-01-05 08:16:05

标签: api youtube

此示例将授权频道订阅到GoogleDevelopers频道。您可以通过更新snippet.resourceId.channelId属性值来更改正在订阅的频道。

 void subscribeYoutube() {

            YouTube youtube = getYouTubeService();
            try {
                HashMap<String, String> parameters = new HashMap<>();
                parameters.put("part", "snippet");


                Subscription subscription = new Subscription();
                SubscriptionSnippet snippet = new SubscriptionSnippet();
                ResourceId resourceId = new ResourceId();
                resourceId.set("channelId", "UC_x5XG1OV2P6uZZ5FSM9Ttw");
                resourceId.set("kind", "youtube#channel");

                snippet.setResourceId(resourceId);
                subscription.setSnippet(snippet);

                YouTube.Subscriptions.Insert subscriptionsInsertRequest = youtube.subscriptions().insert(parameters.get("part").toString(), subscription);

                Subscription response = subscriptionsInsertRequest.execute();

            } catch (IOException e) {

            }

        } 

YouTube can't resolve symbol.Let me known which dependency required for it. 

1 个答案:

答案 0 :(得分:0)

 Sample code can be found on this given links :- 
 https://github.com/youtube/api-samples/tree/master/java

 Depdencies are as below :- 
 compile 'com.google.api-client:google-api-client:1.23.0'
 compile 'com.google.oauth-client:google-oauth-client-jetty:1.23.0'
 compile 'com.google.apis:google-api-services-youtube:v3-rev189-1.23.0'