本文整理匯總了Java中com.google.api.services.youtube.YouTube類的典型用法代碼示例。如果您正苦於以下問題:Java YouTube類的具體用法?Java YouTube怎麽用?Java YouTube使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
YouTube類屬於com.google.api.services.youtube包,在下文中一共展示了YouTube類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getChannelForUser
import com.google.api.services.youtube.YouTube; //導入依賴的package包/類
@Override
public Channel getChannelForUser(String userId)
{
try
{
YouTube.Channels.List channels = getTubeService().channels().list("snippet");
channels.setKey(getApiKey());
channels.setForUsername(userId);
ChannelListResponse channelListResponse = channels.execute();
List<Channel> items = channelListResponse.getItems();
return Check.isEmpty(items) ? null : items.get(0);
}
catch( Exception ex )
{
throw Throwables.propagate(ex);
}
}
示例2: getChannels
import com.google.api.services.youtube.YouTube; //導入依賴的package包/類
@Override
public List<Channel> getChannels(List<String> channelIds)
{
try
{
YouTube.Channels.List channels = getTubeService().channels().list("snippet");
channels.setKey(getApiKey());
channels.setId(Joiner.on(",").join(channelIds));
ChannelListResponse channelListResponse = channels.execute();
return channelListResponse.getItems();
}
catch( Exception ex )
{
throw Throwables.propagate(ex);
}
}
示例3: getVideos
import com.google.api.services.youtube.YouTube; //導入依賴的package包/類
@Override
public List<Video> getVideos(List<String> videoIds)
{
try
{
YouTube.Videos.List videos = getTubeService().videos().list("id,snippet,player,contentDetails,statistics");
videos.setKey(getApiKey());
videos.setId(Joiner.on(",").join(videoIds));
VideoListResponse vlr = videos.execute();
return vlr.getItems();
}
catch( Exception ex )
{
throw Throwables.propagate(ex);
}
}
示例4: getTubeService
import com.google.api.services.youtube.YouTube; //導入依賴的package包/類
private synchronized YouTube getTubeService()
{
if( tubeService == null )
{
tubeService = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(),
new HttpRequestInitializer()
{
@Override
public void initialize(HttpRequest request) throws IOException
{
// Nothing?
}
}).setApplicationName(EQUELLA).build();
}
return tubeService;
}
示例5: deleteMessage
import com.google.api.services.youtube.YouTube; //導入依賴的package包/類
public void deleteMessage(final String messageId, final Runnable onComplete) {
if (messageId == null || messageId.isEmpty() || executor == null) {
onComplete.run();
return;
}
executor.execute(
new Runnable() {
@Override
public void run() {
try {
YouTube.LiveChatMessages.Delete liveChatDelete =
youtube.liveChatMessages().delete(messageId);
liveChatDelete.execute();
Minecraft.getMinecraft().addScheduledTask(onComplete);
} catch (Throwable t) {
showMessage(t.getMessage(), Minecraft.getMinecraft().player);
t.printStackTrace();
onComplete.run();
}
}
});
}
示例6: YouTubeSingleton
import com.google.api.services.youtube.YouTube; //導入依賴的package包/類
private YouTubeSingleton() {
credential = GoogleAccountCredential.usingOAuth2(
YTApplication.getAppContext(), Arrays.asList(SCOPES))
.setBackOff(new ExponentialBackOff());
youTube = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest httpRequest) throws IOException {
}
}).setApplicationName(YTApplication.getAppContext().getString(R.string.app_name))
.build();
youTubeWithCredentials = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), credential)
.setApplicationName(YTApplication.getAppContext().getString(R.string.app_name))
.build();
}
示例7: YouTubeSingleton
import com.google.api.services.youtube.YouTube; //導入依賴的package包/類
private YouTubeSingleton(Context context)
{
String appName = context.getString(R.string.app_name);
credential = GoogleAccountCredential
.usingOAuth2(context, Arrays.asList(SCOPES))
.setBackOff(new ExponentialBackOff());
youTube = new YouTube.Builder(
new NetHttpTransport(),
new JacksonFactory(),
new HttpRequestInitializer()
{
@Override
public void initialize(HttpRequest httpRequest) throws IOException {}
}
).setApplicationName(appName).build();
youTubeWithCredentials = new YouTube.Builder(
new NetHttpTransport(),
new JacksonFactory(),
credential
).setApplicationName(appName).build();
}
示例8: YoutubeSearcher
import com.google.api.services.youtube.YouTube; //導入依賴的package包/類
public YoutubeSearcher(String apiKey)
{
youtube = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), (HttpRequest request) -> {
}).setApplicationName(SpConst.BOTNAME).build();
Search.List tmp = null;
try {
tmp = youtube.search().list("id,snippet");
} catch (IOException ex) {
SimpleLog.getLog("Youtube").fatal("Failed to initialize search: "+ex.toString());
}
search = tmp;
if(search!=null)
{
search.setKey(apiKey);
search.setType("video");
search.setFields("items(id/kind,id/videoId,snippet/title,snippet/thumbnails/default/url)");
}
}
示例9: fetch
import com.google.api.services.youtube.YouTube; //導入依賴的package包/類
@Override
public Video fetch(String query) {
if (!isInitialized()) {
init();
}
YouTube.Search.List search = searchConfig(query);
Video video = null;
try {
List<SearchResult> searchResultList = search.execute().getItems();
if (searchResultList != null) {
String videoId = getVideoId(searchResultList.iterator());
video = new Video(videoId);
}
} catch (IOException e) {
logger.error("Unable to get video for query %s", query);
}
return video;
}
示例10: searchConfig
import com.google.api.services.youtube.YouTube; //導入依賴的package包/類
private YouTube.Search.List searchConfig(String query) {
try {
YouTube.Search.List search = youtube.search().list("id,snippet");
String apiKey = config.getYoutubeApiKey();
search.setKey(apiKey);
search.setQ(query + " review");
// Restrict the search results to only include videos. See:
search.setType("video");
// To increase efficiency, only retrieve the fields that the
// application uses.
search.setFields("items(id/kind,id/videoId,snippet/title,snippet/publishedAt)");
search.setMaxResults(NUMBER_OF_VIDEOS_RETURNED);
search.setOrder("viewCount");
search.setVideoEmbeddable("true");
return search;
} catch (IOException e) {
logger.error("Unable to setup searcher for query "+query);
throw new RuntimeException();
}
}
示例11: handleCommand
import com.google.api.services.youtube.YouTube; //導入依賴的package包/類
@Override
public void handleCommand(String sender, MessageEvent event, String command, String[] args) {
if (command.equals(".youtube") || command.equals(".yt")) {
// Perform search
String query = StringUtils.join(args, " ");
try {
YouTube.Search.List search = youtube.search().list("id,snippet");
search.setKey(SettingsManager.getInstance().getSettings().getYoutubeKey());
search.setQ(query);
search.setMaxResults(1L);
search.setType("video");
SearchListResponse searchListResponse = search.execute();
List<SearchResult> searchResults = searchListResponse.getItems();
if (searchResults != null) {
SearchResult firstResult = searchResults.get(0);
event.getBot().sendIRC().message(event.getChannel().getName(), formatSearchResult(firstResult));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例12: YouTubeRetriever
import com.google.api.services.youtube.YouTube; //導入依賴的package包/類
public YouTubeRetriever(Credentials credentials) throws Exception {
super(credentials);
if (credentials.getClientId() == null || credentials.getKey() == null) {
logger.error("YouTube requires authentication.");
throw new Exception("YouTube requires authentication.");
}
apiKey = credentials.getKey();
youtube = new YouTube.Builder(
HTTP_TRANSPORT,
JSON_FACTORY,
new HttpRequestInitializer() {
public void initialize(HttpRequest request) throws IOException {
}
}
).setApplicationName(credentials.getClientId()).build();
}
示例13: YoutubeConnector
import com.google.api.services.youtube.YouTube; //導入依賴的package包/類
public YoutubeConnector(Context context) {
youtube = new YouTube.Builder(new NetHttpTransport(),
new JacksonFactory(), new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest hr) throws IOException {}
}).setApplicationName(context.getString(R.string.app_name)).build();
try{
// Setting search query
query = youtube.search().list("id,snippet");
query.setKey(KEY);
query.setType("video");
query.setFields("items(id/videoId,snippet/title,snippet/description,snippet/thumbnails/default/url)");
}catch(IOException e){
query = null;
}
}
示例14: listByCandidate
import com.google.api.services.youtube.YouTube; //導入依賴的package包/類
public List<Publication> listByCandidate(final Candidate candidate, final Date lastExecutionDate) throws Throwable{
final List<Publication> result = new ArrayList<Publication>();
try {
//create query
final String query = String.format("%s %s", candidate.getFullName(), candidate.getArabicFullName());
//create the request
final YouTube.Search.List searchRequest = createSearchRequest(query, new DateTime(lastExecutionDate));
//call youtube api
final SearchListResponse searchListResponse = searchRequest.execute();
//serialize response
for (SearchResult searchResult : searchListResponse.getItems()) {
result.add(new Publication(searchResult, candidate));
}
} catch (Throwable e) {
log.error(String.format("Exception when call Youtube API for candidate id=%s", candidate.getId()), e);
throw e;
}
return result;
}
示例15: upload
import com.google.api.services.youtube.YouTube; //導入依賴的package包/類
@Override
public void upload(final File thumbnail, final String videoid, final Account account) throws FileNotFoundException, ThumbnailIOException {
if (!thumbnail.exists()) {
throw new FileNotFoundException(thumbnail.getName());
}
final YouTube youTube = youTubeProvider.setAccount(account).get();
try (final BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(thumbnail))) {
youTube.thumbnails()
.set(videoid, new InputStreamContent("application/octet-stream", bufferedInputStream))
.execute();
} catch (final IOException e) {
throw new ThumbnailIOException(e);
}
}