此示例将授权频道订阅到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.
答案 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'