YouTube API v3-lista przesłanych filmów
Jak wyświetlić listę przesłanych filmów użytkownika w interfejsie API V3?
2 answers
Pierwszym krokiem jest uzyskanie identyfikatora kanału dla tego użytkownika. Możemy to zrobić za pomocą prośby do serwisu Channels
. Oto przykład JS.
var request = gapi.client.youtube.channels.list({
// mine: true indicates that we want to retrieve the channel for the authenticated user.
mine: true,
part: 'contentDetails'
});
request.execute(function(response) {
playlistId = response.result.channels[0].contentDetails.uploads;
});
Po otrzymaniu identyfikatora listy odtwarzania możemy użyć go do wyszukania listy przesłanych filmów z usługi PlaylistItems
.
var request = gapi.client.youtube.playlistItems.list({
playlistId: playlistId,
part: 'snippet',
});
request.execute(function(response) {
// Go through response.result.playlistItems to view list of uploaded videos.
});
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-02-24 18:38:03
Jeśli korzystasz z klienta, odpowiedź Grega jest prawidłowa. Aby zrobić to samo z podstawowymi żądaniami, wykonaj następujące 2 żądania:
-
GET https://www.googleapis.com/youtube/v3/channels
Z parametrami:
part=contentDetails mine=true key={YOUR_API_KEY}
I nagłówek:
Authorization: Bearer {Your access token}
Z tego otrzymasz odpowiedź JSON w ten sposób:
{ "kind": "youtube#channelListResponse", "etag": "\"some-string\"", "pageInfo": { "totalResults": 1, "resultsPerPage": 1 }, "items": [ { "id": "some-id", "kind": "youtube#channel", "etag": "\"another-string\"", "contentDetails": { "relatedPlaylists": { "likes": "channel-id-for-your-likes", "favorites": "channel-id-for-your-favorites", "uploads": "channel-id-for-your-uploads", "watchHistory": "channel-id-for-your-watch-history", "watchLater": "channel-id-for-your-watch-later" } } } ] }
Z tego chcesz przeanalizować identyfikator kanału "uploads".
-
GET https://www.googleapis.com/youtube/v3/playlistItems
Z parametrami:
part=snippet maxResults=50 playlistId={YOUR_UPLOAD_PLAYLIST_ID} key={YOUR_API_KEY}
I nagłówki:
Authorization: Bearer {YOUR_TOKEN}
Od tego otrzymasz odpowiedź JSON jak poniżej:
{ "kind": "youtube#playlistItemListResponse", "etag": "\"some-string\"", "pageInfo": { "totalResults": 1, "resultsPerPage": 50 }, "items": [ { "id": "some-id", "kind": "youtube#playlistItem", "etag": "\"another-string\"", "snippet": { "publishedAt": "some-date", "channelId": "the-channel-id", "title": "video-title", "thumbnails": { "default": { "url": "thumbnail-address" }, "medium": { "url": "thumbnail-address" }, "high": { "url": "thumbnail-address" } }, "playlistId": "upload-playlist-id", "position": 0, "resourceId": { "kind": "youtube#video", "videoId": "the-videos-id" } } } ] }
Dzięki tej metodzie powinieneś być w stanie uzyskać informacje za pomocą dowolnego języka lub nawet po prostu curl. Jeśli chcesz więcej niż pierwszych 50 wyników, będziesz musiał wykonać wiele zapytań za pomocą drugiego żądania i przekazać żądania strony. Więcej na ten temat można przeczytać na: http://developers.google.com/youtube/v3/docs/playlistItems/list
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-11-26 17:48:03