的Topics.java
文件演示-ING的Topics API,我認爲這是不是你想要做的更多。
要簡單瞭解視頻ID的詳細信息,請查看Videos.list
。您可以使用頁面底部的API瀏覽器創建基本請求,例如
GET https://www.googleapis.com/youtube/v3/videos?
part=id%2Csnippet&id=5vY8EWokf40&key={YOUR_API_KEY}
...返回:
{
"kind": "youtube#videoListResponse",
"etag": "\"5g01s4-wS2b4VpScndqCYc5Y-8k/v-nx5E3jmblZ7cA3yNCjAAKmywQ\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "\"5g01s4-wS2b4VpScndqCYc5Y-8k/rsLwePwmFcmdkMVDPrQB20sLp1Q\"",
"id": "5vY8EWokf40",
"snippet": {
"publishedAt": "2015-06-27T03:02:46.000Z",
"channelId": "UCz0Am9KlCDydaIifIL16hfw",
"title": "Hajar Film - Sirin Hamsho | فيلم هاجر - سيرين حمشو",
...
要做到這一點在Java中,看看在同一頁上的示例部分。基本上,您需要創建一個com.google.api.services.youtube.YouTube
對象,請撥打videos().list()
,並處理VideoListResponse
。
望着JAVA#2的例子,你可以看到這個證明是:
// 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();
...
// Call the YouTube Data API's videos.list method to retrieve videos.
VideoListResponse videoListResponse = youtube.videos().
list("snippet,localizations").setId(videoId).execute();
// Since the API request specified a unique video ID, the API
// response should return exactly one video. If the response does
// not contain a video, then the specified video ID was not found.
List<Video> videoList = videoListResponse.getItems();
if (videoList.isEmpty()) {
System.out.println("Can't find a video with ID: " + videoId);
return;
}
Video video = videoList.get(0);
你可以看一下在JavaDoc reference for the YouTube Data API關於使用Java庫的更多細節。
導入com.google.api.services.youtube.model.VideoLocalization時出錯。請使用命令行的屏幕截圖查看更新後的問題。 –
通過添加之前引用107的176版本來修復上述問題。但它仍會在第193行拋出一個空指針異常。問題用屏幕截圖進行更新。 –
簡單的GET請求起作用。謝謝! –