當前位置: 首頁>>代碼示例>>Java>>正文


Java YouTube類代碼示例

本文整理匯總了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);
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:20,代碼來源:GoogleServiceImpl.java

示例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);
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:18,代碼來源:GoogleServiceImpl.java

示例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);
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:18,代碼來源:GoogleServiceImpl.java

示例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;
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:17,代碼來源:GoogleServiceImpl.java

示例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();
          }
        }
      });
}
 
開發者ID:youtube,項目名稱:youtube-chat-for-minecraft,代碼行數:24,代碼來源:ChatService.java

示例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();
    }
 
開發者ID:pawelpaszki,項目名稱:youtube_background_android,代碼行數:19,代碼來源:YouTubeSingleton.java

示例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();
}
 
開發者ID:teocci,項目名稱:YouTube-In-Background,代碼行數:24,代碼來源:YouTubeSingleton.java

示例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)");
    }
}
 
開發者ID:jagrosh,項目名稱:Spectra,代碼行數:19,代碼來源:YoutubeSearcher.java

示例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;
}
 
開發者ID:victor-guoyu,項目名稱:Review-It,代碼行數:19,代碼來源:YouTubeCrawler.java

示例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();
    }
}
 
開發者ID:victor-guoyu,項目名稱:Review-It,代碼行數:24,代碼來源:YouTubeCrawler.java

示例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();
		}
	}
}
 
開發者ID:MCUpdater,項目名稱:RavenBot,代碼行數:24,代碼來源:YouTubeHandler.java

示例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();
}
 
開發者ID:MKLab-ITI,項目名稱:simmo-stream-manager,代碼行數:20,代碼來源:YouTubeRetriever.java

示例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;
    }
}
 
開發者ID:leftdal,項目名稱:youslow,代碼行數:18,代碼來源:YoutubeConnector.java

示例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;
}
 
開發者ID:ayassinov,項目名稱:tnpresidential,代碼行數:26,代碼來源:YoutubeClient.java

示例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);
	}
}
 
開發者ID:dennisfischer,項目名稱:simplejavayoutubeuploader,代碼行數:17,代碼來源:ThumbnailServiceImpl.java


注:本文中的com.google.api.services.youtube.YouTube類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。