use of org.openstack4j.model.identity.v3.Credential in project api-samples by youtube.
the class InvideoProgramming method main.
/**
* This code sample demonstrates different ways that the API can be used to
* promote your channel content. It includes code for the following tasks:
* <ol>
* <li>Feature a video.</li>
* <li>Feature a link to a social media channel.</li>
* <li>Set a watermark for videos on your channel.</li>
* </ol>
*
* @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, "invideoprogramming");
// This object is used to make YouTube Data API requests.
youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential).setApplicationName("youtube-cmdline-invideoprogramming-sample").build();
// Construct a request to retrieve the current user's channel ID.
// In the API response, only include channel information needed for
// this use case. The channel's uploads playlist identifies the
// channel's most recently uploaded video.
// See https://developers.google.com/youtube/v3/docs/channels/list
ChannelListResponse channelListResponse = youtube.channels().list("id,contentDetails").setMine(true).setFields("items(contentDetails/relatedPlaylists/uploads,id)").execute();
// The user's default channel is the first item in the list. If the
// user does not have a channel, this code should throw a
// GoogleJsonResponseException explaining the issue.
Channel myChannel = channelListResponse.getItems().get(0);
String channelId = myChannel.getId();
// The promotion appears 15000ms (15 seconds) before the video ends.
InvideoTiming invideoTiming = new InvideoTiming();
invideoTiming.setOffsetMs(BigInteger.valueOf(15000l));
invideoTiming.setType("offsetFromEnd");
// This is one type of promotion and promotes a video.
PromotedItemId promotedItemId = new PromotedItemId();
promotedItemId.setType("video");
promotedItemId.setVideoId(FEATURED_VIDEO_ID);
// Set a custom message providing additional information about the
// promoted video or your channel.
PromotedItem promotedItem = new PromotedItem();
promotedItem.setCustomMessage("Check out this video about WebM!");
promotedItem.setId(promotedItemId);
// Construct an object representing the invideo promotion data, and
// add it to the channel.
InvideoPromotion invideoPromotion = new InvideoPromotion();
invideoPromotion.setDefaultTiming(invideoTiming);
invideoPromotion.setItems(Lists.newArrayList(promotedItem));
Channel channel = new Channel();
channel.setId(channelId);
channel.setInvideoPromotion(invideoPromotion);
Channel updateChannelResponse = youtube.channels().update("invideoPromotion", channel).execute();
// Print data from the API response.
System.out.println("\n================== Updated Channel Information ==================\n");
System.out.println("\t- Channel ID: " + updateChannelResponse.getId());
InvideoPromotion promotions = updateChannelResponse.getInvideoPromotion();
// We only care about the first item
promotedItem = promotions.getItems().get(0);
System.out.println("\t- Invideo promotion video ID: " + promotedItem.getId().getVideoId());
System.out.println("\t- Promotion message: " + promotedItem.getCustomMessage());
// In-video programming can also be used to feature links to
// associated websites, merchant sites, or social networking sites.
// The code below overrides the promotional video set above by
// featuring a link to the YouTube Developers Twitter feed.
PromotedItemId promotedTwitterFeed = new PromotedItemId();
promotedTwitterFeed.setType("website");
promotedTwitterFeed.setWebsiteUrl("https://twitter.com/youtubedev");
promotedItem = new PromotedItem();
promotedItem.setCustomMessage("Follow us on Twitter!");
promotedItem.setId(promotedTwitterFeed);
invideoPromotion.setItems(Lists.newArrayList(promotedItem));
channel.setInvideoPromotion(invideoPromotion);
// Call the API to set the in-video promotion data.
updateChannelResponse = youtube.channels().update("invideoPromotion", channel).execute();
// Print data from the API response.
System.out.println("\n================== Updated Channel Information ==================\n");
System.out.println("\t- Channel ID: " + updateChannelResponse.getId());
promotions = updateChannelResponse.getInvideoPromotion();
promotedItem = promotions.getItems().get(0);
System.out.println("\t- Invideo promotion URL: " + promotedItem.getId().getWebsiteUrl());
System.out.println("\t- Promotion message: " + promotedItem.getCustomMessage());
// This example sets a custom watermark for the channel. The image
// used is the watermark.jpg file in the "resources/" directory.
InputStreamContent mediaContent = new InputStreamContent("image/jpeg", InvideoProgramming.class.getResourceAsStream("/watermark.jpg"));
// Indicate that the watermark should display during the last 15
// seconds of the video.
InvideoTiming watermarkTiming = new InvideoTiming();
watermarkTiming.setType("offsetFromEnd");
watermarkTiming.setDurationMs(BigInteger.valueOf(15000l));
watermarkTiming.setOffsetMs(BigInteger.valueOf(15000l));
InvideoBranding invideoBranding = new InvideoBranding();
invideoBranding.setTiming(watermarkTiming);
youtube.watermarks().set(channelId, invideoBranding, mediaContent).execute();
} 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();
}
}
use of org.openstack4j.model.identity.v3.Credential in project api-samples by youtube.
the class MyUploads method main.
/**
* Authorize the user, call the youtube.channels.list method to retrieve
* the playlist ID for the list of videos uploaded to the user's channel,
* and then call the youtube.playlistItems.list method to retrieve the
* list of videos in that playlist.
*
* @param args command line args (not used).
*/
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, "myuploads");
// This object is used to make YouTube Data API requests.
youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential).setApplicationName("youtube-cmdline-myuploads-sample").build();
// Call the API's channels.list method to retrieve the
// resource that represents the authenticated user's channel.
// In the API response, only include channel information needed for
// this use case. The channel's contentDetails part contains
// playlist IDs relevant to the channel, including the ID for the
// list that contains videos uploaded to the channel.
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();
if (channelsList != null) {
// The user's default channel is the first item in the list.
// Extract the playlist ID for the channel's videos from the
// API response.
String uploadPlaylistId = channelsList.get(0).getContentDetails().getRelatedPlaylists().getUploads();
// Define a list to store items in the list of uploaded videos.
List<PlaylistItem> playlistItemList = new ArrayList<PlaylistItem>();
// Retrieve the playlist of the channel's uploaded videos.
YouTube.PlaylistItems.List playlistItemRequest = youtube.playlistItems().list("id,contentDetails,snippet");
playlistItemRequest.setPlaylistId(uploadPlaylistId);
// Only retrieve data used in this application, thereby making
// the application more efficient. See:
// https://developers.google.com/youtube/v3/getting-started#partial
playlistItemRequest.setFields("items(contentDetails/videoId,snippet/title,snippet/publishedAt),nextPageToken,pageInfo");
String nextToken = "";
// there are still more items to retrieve.
do {
playlistItemRequest.setPageToken(nextToken);
PlaylistItemListResponse playlistItemResult = playlistItemRequest.execute();
playlistItemList.addAll(playlistItemResult.getItems());
nextToken = playlistItemResult.getNextPageToken();
} while (nextToken != null);
// Prints information about the results.
prettyPrint(playlistItemList.size(), playlistItemList.iterator());
}
} catch (GoogleJsonResponseException e) {
e.printStackTrace();
System.err.println("There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage());
} catch (Throwable t) {
t.printStackTrace();
}
}
use of org.openstack4j.model.identity.v3.Credential in project api-samples by youtube.
the class PlaylistLocalizations method main.
/**
* Set and retrieve localized metadata for a playlist.
*
* @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:
setPlaylistLocalization(getId("playlist"), getDefaultLanguage(), getLanguage(), getMetadata("title"), getMetadata("description"));
break;
case GET:
getPlaylistLocalization(getId("playlist"), getLanguage());
break;
case LIST:
listPlaylistLocalizations(getId("playlist"));
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 PlaylistUpdates method main.
/**
* Authorize the user, create a playlist, and add an item to the playlist.
*
* @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, "playlistupdates");
// This object is used to make YouTube Data API requests.
youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential).setApplicationName("youtube-cmdline-playlistupdates-sample").build();
// Create a new, private playlist in the authorized user's channel.
String playlistId = insertPlaylist();
// If a valid playlist was created, add a video to that playlist.
insertPlaylistItem(playlistId, VIDEO_ID);
} catch (GoogleJsonResponseException e) {
System.err.println("There was a service error: " + 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 ChannelBulletin method main.
/**
* Authorize the user, call the youtube.channels.list method to retrieve
* information about the user's YouTube channel, and post a bulletin with
* a video ID to that 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, "channelbulletin");
// This object is used to make YouTube Data API requests.
youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential).setApplicationName("youtube-cmdline-channelbulletin-sample").build();
// Construct a request to retrieve the current user's channel ID.
// See https://developers.google.com/youtube/v3/docs/channels/list
YouTube.Channels.List channelRequest = youtube.channels().list("contentDetails");
channelRequest.setMine(true);
// In the API response, only include channel information needed
// for this use case.
channelRequest.setFields("items/contentDetails");
ChannelListResponse channelResult = channelRequest.execute();
List<Channel> channelsList = channelResult.getItems();
if (channelsList != null) {
// The user's default channel is the first item in the list.
String channelId = channelsList.get(0).getId();
// Create the snippet for the activity resource that
// represents the channel bulletin. Set its channel ID
// and description.
ActivitySnippet snippet = new ActivitySnippet();
snippet.setChannelId(channelId);
Calendar cal = Calendar.getInstance();
snippet.setDescription("Bulletin test video via YouTube API on " + cal.getTime());
// Create a resourceId that identifies the video ID. You could
// set the kind to "youtube#playlist" and use a playlist ID
// instead of a video ID.
ResourceId resource = new ResourceId();
resource.setKind("youtube#video");
resource.setVideoId(VIDEO_ID);
ActivityContentDetailsBulletin bulletin = new ActivityContentDetailsBulletin();
bulletin.setResourceId(resource);
// Construct the ActivityContentDetails object for the request.
ActivityContentDetails contentDetails = new ActivityContentDetails();
contentDetails.setBulletin(bulletin);
// Construct the resource, including the snippet and content
// details, to send in the activities.insert
Activity activity = new Activity();
activity.setSnippet(snippet);
activity.setContentDetails(contentDetails);
// The API request identifies the resource parts that are being
// written (contentDetails and snippet). The API response will
// also include those parts.
YouTube.Activities.Insert insertActivities = youtube.activities().insert("contentDetails,snippet", activity);
// Return the newly created activity resource.
Activity newActivityInserted = insertActivities.execute();
if (newActivityInserted != null) {
System.out.println("New Activity inserted of type " + newActivityInserted.getSnippet().getType());
System.out.println(" - Video id " + newActivityInserted.getContentDetails().getBulletin().getResourceId().getVideoId());
System.out.println(" - Description: " + newActivityInserted.getSnippet().getDescription());
System.out.println(" - Posted on " + newActivityInserted.getSnippet().getPublishedAt());
} else {
System.out.println("Activity failed.");
}
} else {
System.out.println("No channels are assigned to this user.");
}
} catch (GoogleJsonResponseException e) {
e.printStackTrace();
System.err.println("There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage());
} catch (Throwable t) {
t.printStackTrace();
}
}
Aggregations