use of org.openstack4j.model.identity.v3.Credential in project api-samples by youtube.
the class ChannelLocalizations method main.
/**
* Set and retrieve localized metadata for a channel.
*
* @param args command line args (not used).
*/
public static void main(String[] args) {
// This OAuth 2.0 access scope allows for full read/write access to the
// authenticated user's account.
List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube");
try {
// Authorize the request.
Credential credential = Auth.authorize(scopes, "localizations");
// This object is used to make YouTube Data API requests.
youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential).setApplicationName("youtube-cmdline-localizations-sample").build();
// Prompt the user to specify the action of the be achieved.
String actionString = getActionFromUser();
System.out.println("You chose " + actionString + ".");
//Map the user input to the enum values.
Action action = Action.valueOf(actionString.toUpperCase());
switch(action) {
case SET:
setChannelLocalization(getId("channel"), getDefaultLanguage(), getLanguage(), getMetadata("description"));
break;
case GET:
getChannelLocalization(getId("channel"), getLanguage());
break;
case LIST:
listChannelLocalizations(getId("channel"));
break;
}
} catch (GoogleJsonResponseException e) {
System.err.println("GoogleJsonResponseException code: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage());
e.printStackTrace();
} catch (IOException e) {
System.err.println("IOException: " + e.getMessage());
e.printStackTrace();
} catch (Throwable t) {
System.err.println("Throwable: " + t.getMessage());
t.printStackTrace();
}
}
use of org.openstack4j.model.identity.v3.Credential in project api-samples by youtube.
the class CommentHandling method main.
/**
* List, reply to comment threads; list, update, moderate, mark and delete
* replies.
*
* @param args command line args (not used).
*/
public static void main(String[] args) {
// This OAuth 2.0 access scope allows for full read/write access to the
// authenticated user's account and requires requests to use an SSL connection.
List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube.force-ssl");
try {
// Authorize the request.
Credential credential = Auth.authorize(scopes, "commentthreads");
// This object is used to make YouTube Data API requests.
youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential).setApplicationName("youtube-cmdline-commentthreads-sample").build();
// Prompt the user for the ID of a video to comment on.
// Retrieve the video ID that the user is commenting to.
String videoId = getVideoId();
System.out.println("You chose " + videoId + " to subscribe.");
// Prompt the user for the comment text.
// Retrieve the text that the user is commenting.
String text = getText();
System.out.println("You chose " + text + " to subscribe.");
// All the available methods are used in sequence just for the sake
// of an example.
// Call the YouTube Data API's commentThreads.list method to
// retrieve video comment threads.
CommentThreadListResponse videoCommentsListResponse = youtube.commentThreads().list("snippet").setVideoId(videoId).setTextFormat("plainText").execute();
List<CommentThread> videoComments = videoCommentsListResponse.getItems();
if (videoComments.isEmpty()) {
System.out.println("Can't get video comments.");
} else {
// Print information from the API response.
System.out.println("\n================== Returned Video Comments ==================\n");
for (CommentThread videoComment : videoComments) {
CommentSnippet snippet = videoComment.getSnippet().getTopLevelComment().getSnippet();
System.out.println(" - Author: " + snippet.getAuthorDisplayName());
System.out.println(" - Comment: " + snippet.getTextDisplay());
System.out.println("\n-------------------------------------------------------------\n");
}
CommentThread firstComment = videoComments.get(0);
// Will use this thread as parent to new reply.
String parentId = firstComment.getId();
// Create a comment snippet with text.
CommentSnippet commentSnippet = new CommentSnippet();
commentSnippet.setTextOriginal(text);
commentSnippet.setParentId(parentId);
// Create a comment with snippet.
Comment comment = new Comment();
comment.setSnippet(commentSnippet);
// Call the YouTube Data API's comments.insert method to reply
// to a comment.
// (If the intention is to create a new top-level comment,
// commentThreads.insert
// method should be used instead.)
Comment commentInsertResponse = youtube.comments().insert("snippet", comment).execute();
// Print information from the API response.
System.out.println("\n================== Created Comment Reply ==================\n");
CommentSnippet snippet = commentInsertResponse.getSnippet();
System.out.println(" - Author: " + snippet.getAuthorDisplayName());
System.out.println(" - Comment: " + snippet.getTextDisplay());
System.out.println("\n-------------------------------------------------------------\n");
// Call the YouTube Data API's comments.list method to retrieve
// existing comment
// replies.
CommentListResponse commentsListResponse = youtube.comments().list("snippet").setParentId(parentId).setTextFormat("plainText").execute();
List<Comment> comments = commentsListResponse.getItems();
if (comments.isEmpty()) {
System.out.println("Can't get comment replies.");
} else {
// Print information from the API response.
System.out.println("\n================== Returned Comment Replies ==================\n");
for (Comment commentReply : comments) {
snippet = commentReply.getSnippet();
System.out.println(" - Author: " + snippet.getAuthorDisplayName());
System.out.println(" - Comment: " + snippet.getTextDisplay());
System.out.println("\n-------------------------------------------------------------\n");
}
Comment firstCommentReply = comments.get(0);
firstCommentReply.getSnippet().setTextOriginal("updated");
Comment commentUpdateResponse = youtube.comments().update("snippet", firstCommentReply).execute();
// Print information from the API response.
System.out.println("\n================== Updated Video Comment ==================\n");
snippet = commentUpdateResponse.getSnippet();
System.out.println(" - Author: " + snippet.getAuthorDisplayName());
System.out.println(" - Comment: " + snippet.getTextDisplay());
System.out.println("\n-------------------------------------------------------------\n");
// Call the YouTube Data API's comments.setModerationStatus
// method to set moderation
// status of an existing comment.
youtube.comments().setModerationStatus(firstCommentReply.getId(), "published");
System.out.println(" - Changed comment status to published: " + firstCommentReply.getId());
// Call the YouTube Data API's comments.markAsSpam method to
// mark an existing comment as spam.
youtube.comments().markAsSpam(firstCommentReply.getId());
System.out.println(" - Marked comment as spam: " + firstCommentReply.getId());
// Call the YouTube Data API's comments.delete method to
// delete an existing comment.
youtube.comments().delete(firstCommentReply.getId());
System.out.println(" - Deleted comment as spam: " + firstCommentReply.getId());
}
}
} catch (GoogleJsonResponseException e) {
System.err.println("GoogleJsonResponseException code: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage());
e.printStackTrace();
} catch (IOException e) {
System.err.println("IOException: " + e.getMessage());
e.printStackTrace();
} catch (Throwable t) {
System.err.println("Throwable: " + t.getMessage());
t.printStackTrace();
}
}
use of org.openstack4j.model.identity.v3.Credential in project api-samples by youtube.
the class CommentThreads method main.
/**
* Create, list and update top-level channel and video comments.
*
* @param args command line args (not used).
*/
public static void main(String[] args) {
// This OAuth 2.0 access scope allows for full read/write access to the
// authenticated user's account and requires requests to use an SSL connection.
List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube.force-ssl");
try {
// Authorize the request.
Credential credential = Auth.authorize(scopes, "commentthreads");
// This object is used to make YouTube Data API requests.
youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential).setApplicationName("youtube-cmdline-commentthreads-sample").build();
// Prompt the user for the ID of a channel to comment on.
// Retrieve the channel ID that the user is commenting to.
String channelId = getChannelId();
System.out.println("You chose " + channelId + " to subscribe.");
// Prompt the user for the ID of a video to comment on.
// Retrieve the video ID that the user is commenting to.
String videoId = getVideoId();
System.out.println("You chose " + videoId + " to subscribe.");
// Prompt the user for the comment text.
// Retrieve the text that the user is commenting.
String text = getText();
System.out.println("You chose " + text + " to subscribe.");
// Insert channel comment by omitting videoId.
// Create a comment snippet with text.
CommentSnippet commentSnippet = new CommentSnippet();
commentSnippet.setTextOriginal(text);
// Create a top-level comment with snippet.
Comment topLevelComment = new Comment();
topLevelComment.setSnippet(commentSnippet);
// Create a comment thread snippet with channelId and top-level
// comment.
CommentThreadSnippet commentThreadSnippet = new CommentThreadSnippet();
commentThreadSnippet.setChannelId(channelId);
commentThreadSnippet.setTopLevelComment(topLevelComment);
// Create a comment thread with snippet.
CommentThread commentThread = new CommentThread();
commentThread.setSnippet(commentThreadSnippet);
// Call the YouTube Data API's commentThreads.insert method to
// create a comment.
CommentThread channelCommentInsertResponse = youtube.commentThreads().insert("snippet", commentThread).execute();
// Print information from the API response.
System.out.println("\n================== Created Channel Comment ==================\n");
CommentSnippet snippet = channelCommentInsertResponse.getSnippet().getTopLevelComment().getSnippet();
System.out.println(" - Author: " + snippet.getAuthorDisplayName());
System.out.println(" - Comment: " + snippet.getTextDisplay());
System.out.println("\n-------------------------------------------------------------\n");
// Insert video comment
commentThreadSnippet.setVideoId(videoId);
// Call the YouTube Data API's commentThreads.insert method to
// create a comment.
CommentThread videoCommentInsertResponse = youtube.commentThreads().insert("snippet", commentThread).execute();
// Print information from the API response.
System.out.println("\n================== Created Video Comment ==================\n");
snippet = videoCommentInsertResponse.getSnippet().getTopLevelComment().getSnippet();
System.out.println(" - Author: " + snippet.getAuthorDisplayName());
System.out.println(" - Comment: " + snippet.getTextDisplay());
System.out.println("\n-------------------------------------------------------------\n");
// Call the YouTube Data API's commentThreads.list method to
// retrieve video comment threads.
CommentThreadListResponse videoCommentsListResponse = youtube.commentThreads().list("snippet").setVideoId(videoId).setTextFormat("plainText").execute();
List<CommentThread> videoComments = videoCommentsListResponse.getItems();
if (videoComments.isEmpty()) {
System.out.println("Can't get video comments.");
} else {
// Print information from the API response.
System.out.println("\n================== Returned Video Comments ==================\n");
for (CommentThread videoComment : videoComments) {
snippet = videoComment.getSnippet().getTopLevelComment().getSnippet();
System.out.println(" - Author: " + snippet.getAuthorDisplayName());
System.out.println(" - Comment: " + snippet.getTextDisplay());
System.out.println("\n-------------------------------------------------------------\n");
}
CommentThread firstComment = videoComments.get(0);
firstComment.getSnippet().getTopLevelComment().getSnippet().setTextOriginal("updated");
CommentThread videoCommentUpdateResponse = youtube.commentThreads().update("snippet", firstComment).execute();
// Print information from the API response.
System.out.println("\n================== Updated Video Comment ==================\n");
snippet = videoCommentUpdateResponse.getSnippet().getTopLevelComment().getSnippet();
System.out.println(" - Author: " + snippet.getAuthorDisplayName());
System.out.println(" - Comment: " + snippet.getTextDisplay());
System.out.println("\n-------------------------------------------------------------\n");
}
// Call the YouTube Data API's commentThreads.list method to
// retrieve channel comment threads.
CommentThreadListResponse channelCommentsListResponse = youtube.commentThreads().list("snippet").setChannelId(channelId).setTextFormat("plainText").execute();
List<CommentThread> channelComments = channelCommentsListResponse.getItems();
if (channelComments.isEmpty()) {
System.out.println("Can't get channel comments.");
} else {
// Print information from the API response.
System.out.println("\n================== Returned Channel Comments ==================\n");
for (CommentThread channelComment : channelComments) {
snippet = channelComment.getSnippet().getTopLevelComment().getSnippet();
System.out.println(" - Author: " + snippet.getAuthorDisplayName());
System.out.println(" - Comment: " + snippet.getTextDisplay());
System.out.println("\n-------------------------------------------------------------\n");
}
CommentThread firstComment = channelComments.get(0);
firstComment.getSnippet().getTopLevelComment().getSnippet().setTextOriginal("updated");
CommentThread channelCommentUpdateResponse = youtube.commentThreads().update("snippet", firstComment).execute();
// Print information from the API response.
System.out.println("\n================== Updated Channel Comment ==================\n");
snippet = channelCommentUpdateResponse.getSnippet().getTopLevelComment().getSnippet();
System.out.println(" - Author: " + snippet.getAuthorDisplayName());
System.out.println(" - Comment: " + snippet.getTextDisplay());
System.out.println("\n-------------------------------------------------------------\n");
}
} catch (GoogleJsonResponseException e) {
System.err.println("GoogleJsonResponseException code: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage());
e.printStackTrace();
} catch (IOException e) {
System.err.println("IOException: " + e.getMessage());
e.printStackTrace();
} catch (Throwable t) {
System.err.println("Throwable: " + t.getMessage());
t.printStackTrace();
}
}
use of org.openstack4j.model.identity.v3.Credential in project api-samples by youtube.
the class CreateBroadcast method main.
/**
* Create and insert a liveBroadcast resource.
*/
public static void main(String[] args) {
// This OAuth 2.0 access scope allows for full read/write access to the
// authenticated user's account.
List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube");
try {
// Authorize the request.
Credential credential = Auth.authorize(scopes, "createbroadcast");
// This object is used to make YouTube Data API requests.
youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential).setApplicationName("youtube-cmdline-createbroadcast-sample").build();
// Prompt the user to enter a title for the broadcast.
String title = getBroadcastTitle();
System.out.println("You chose " + title + " for broadcast title.");
// Create a snippet with the title and scheduled start and end
// times for the broadcast. Currently, those times are hard-coded.
LiveBroadcastSnippet broadcastSnippet = new LiveBroadcastSnippet();
broadcastSnippet.setTitle(title);
broadcastSnippet.setScheduledStartTime(new DateTime("2024-01-30T00:00:00.000Z"));
broadcastSnippet.setScheduledEndTime(new DateTime("2024-01-31T00:00:00.000Z"));
// Set the broadcast's privacy status to "private". See:
// https://developers.google.com/youtube/v3/live/docs/liveBroadcasts#status.privacyStatus
LiveBroadcastStatus status = new LiveBroadcastStatus();
status.setPrivacyStatus("private");
LiveBroadcast broadcast = new LiveBroadcast();
broadcast.setKind("youtube#liveBroadcast");
broadcast.setSnippet(broadcastSnippet);
broadcast.setStatus(status);
// Construct and execute the API request to insert the broadcast.
YouTube.LiveBroadcasts.Insert liveBroadcastInsert = youtube.liveBroadcasts().insert("snippet,status", broadcast);
LiveBroadcast returnedBroadcast = liveBroadcastInsert.execute();
// Print information from the API response.
System.out.println("\n================== Returned Broadcast ==================\n");
System.out.println(" - Id: " + returnedBroadcast.getId());
System.out.println(" - Title: " + returnedBroadcast.getSnippet().getTitle());
System.out.println(" - Description: " + returnedBroadcast.getSnippet().getDescription());
System.out.println(" - Published At: " + returnedBroadcast.getSnippet().getPublishedAt());
System.out.println(" - Scheduled Start Time: " + returnedBroadcast.getSnippet().getScheduledStartTime());
System.out.println(" - Scheduled End Time: " + returnedBroadcast.getSnippet().getScheduledEndTime());
// Prompt the user to enter a title for the video stream.
title = getStreamTitle();
System.out.println("You chose " + title + " for stream title.");
// Create a snippet with the video stream's title.
LiveStreamSnippet streamSnippet = new LiveStreamSnippet();
streamSnippet.setTitle(title);
// Define the content distribution network settings for the
// video stream. The settings specify the stream's format and
// ingestion type. See:
// https://developers.google.com/youtube/v3/live/docs/liveStreams#cdn
CdnSettings cdnSettings = new CdnSettings();
cdnSettings.setFormat("1080p");
cdnSettings.setIngestionType("rtmp");
LiveStream stream = new LiveStream();
stream.setKind("youtube#liveStream");
stream.setSnippet(streamSnippet);
stream.setCdn(cdnSettings);
// Construct and execute the API request to insert the stream.
YouTube.LiveStreams.Insert liveStreamInsert = youtube.liveStreams().insert("snippet,cdn", stream);
LiveStream returnedStream = liveStreamInsert.execute();
// Print information from the API response.
System.out.println("\n================== Returned Stream ==================\n");
System.out.println(" - Id: " + returnedStream.getId());
System.out.println(" - Title: " + returnedStream.getSnippet().getTitle());
System.out.println(" - Description: " + returnedStream.getSnippet().getDescription());
System.out.println(" - Published At: " + returnedStream.getSnippet().getPublishedAt());
// Construct and execute a request to bind the new broadcast
// and stream.
YouTube.LiveBroadcasts.Bind liveBroadcastBind = youtube.liveBroadcasts().bind(returnedBroadcast.getId(), "id,contentDetails");
liveBroadcastBind.setStreamId(returnedStream.getId());
returnedBroadcast = liveBroadcastBind.execute();
// Print information from the API response.
System.out.println("\n================== Returned Bound Broadcast ==================\n");
System.out.println(" - Broadcast Id: " + returnedBroadcast.getId());
System.out.println(" - Bound Stream Id: " + returnedBroadcast.getContentDetails().getBoundStreamId());
} catch (GoogleJsonResponseException e) {
System.err.println("GoogleJsonResponseException code: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage());
e.printStackTrace();
} catch (IOException e) {
System.err.println("IOException: " + e.getMessage());
e.printStackTrace();
} catch (Throwable t) {
System.err.println("Throwable: " + t.getMessage());
t.printStackTrace();
}
}
use of org.openstack4j.model.identity.v3.Credential in project api-samples by youtube.
the class ListStreams method main.
/**
* List streams for the user's channel.
*/
public static void main(String[] args) {
// This OAuth 2.0 access scope allows for read-only access to the
// authenticated user's account, but not other types of account access.
List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube.readonly");
try {
// Authorize the request.
Credential credential = Auth.authorize(scopes, "liststreams");
// This object is used to make YouTube Data API requests.
youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential).setApplicationName("youtube-cmdline-liststreams-sample").build();
// Create a request to list liveStream resources.
YouTube.LiveStreams.List livestreamRequest = youtube.liveStreams().list("id,snippet");
// Modify results to only return the user's streams.
livestreamRequest.setMine(true);
// Execute the API request and return the list of streams.
LiveStreamListResponse returnedListResponse = livestreamRequest.execute();
List<LiveStream> returnedList = returnedListResponse.getItems();
// Print information from the API response.
System.out.println("\n================== Returned Streams ==================\n");
for (LiveStream stream : returnedList) {
System.out.println(" - Id: " + stream.getId());
System.out.println(" - Title: " + stream.getSnippet().getTitle());
System.out.println(" - Description: " + stream.getSnippet().getDescription());
System.out.println(" - Published At: " + stream.getSnippet().getPublishedAt());
System.out.println("\n-------------------------------------------------------------\n");
}
} catch (GoogleJsonResponseException e) {
System.err.println("GoogleJsonResponseException code: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage());
e.printStackTrace();
} catch (IOException e) {
System.err.println("IOException: " + e.getMessage());
e.printStackTrace();
} catch (Throwable t) {
System.err.println("Throwable: " + t.getMessage());
t.printStackTrace();
}
}
Aggregations