• Najnowsze pytania
  • Bez odpowiedzi
  • Zadaj pytanie
  • Kategorie
  • Tagi
  • Zdobyte punkty
  • Ekipa ninja
  • IRC
  • FAQ
  • Regulamin
  • Książki warte uwagi

Lapanie playlisty z youtube w js

VPS Starter Arubacloud
0 głosów
223 wizyt
pytanie zadane 1 sierpnia 2017 w JavaScript przez Alex.Ironside Stary wyjadacz (14,880 p.)

Witam. Chce zlapac id wszystkich filmow w youtubowej playliscie. Mam taki kod

    // Define some variables used to remember state.
    var playlistId = 'PLR1n4Pmhcag4qwvLwGueUHzraCDtC-VjC', nextPageToken, prevPageToken;

    // After the API loads, call a function to get the uploads playlist ID.
    function handleAPILoaded() {
        requestUserUploadsPlaylistId();
    }

    // Call the Data API to retrieve the playlist ID that uniquely identifies the
    // list of videos uploaded to the currently authenticated user's channel.
    function requestUserUploadsPlaylistId() {
        // See https://developers.google.com/youtube/v3/docs/channels/list
        var request = gapi.client.youtube.channels.list({
            mine: true,
            part: 'contentDetails'
        });
        request.execute(function (response) {
            playlistId = response.result.items[0].contentDetails.relatedPlaylists.uploads;
            requestVideoPlaylist(playlistId);
        });
    }

    // Retrieve the list of videos in the specified playlist.
    function requestVideoPlaylist(playlistId, pageToken) {
        $('#video-container').html('');
        var requestOptions = {
            playlistId: playlistId,
            part: 'snippet',
            maxResults: 10
        };
        if (pageToken) {
            requestOptions.pageToken = pageToken;
        }
        var request = gapi.client.youtube.playlistItems.list(requestOptions);
        request.execute(function (response) {
            // Only show pagination buttons if there is a pagination token for the
            // next or previous page of results.
            nextPageToken = response.result.nextPageToken;
            var nextVis = nextPageToken ? 'visible' : 'hidden';
            $('#next-button').css('visibility', nextVis);
            prevPageToken = response.result.prevPageToken
            var prevVis = prevPageToken ? 'visible' : 'hidden';
            $('#prev-button').css('visibility', prevVis);

            var playlistItems = response.result.items;
            if (playlistItems) {
                $.each(playlistItems, function (index, item) {
                    displayResult(item.snippet);
                });
            } else {
                $('#video-container').html('Sorry you have no uploaded videos');
            }
        });
    }

    // Create a listing for a video.
    function displayResult(videoSnippet) {
        var title = videoSnippet.title;
        var videoId = videoSnippet.resourceId.videoId;
        console.log('<p>' + title + ' - ' + videoId + '</p>');
    }

    // Retrieve the next page of videos in the playlist.
    function nextPage() {
        requestVideoPlaylist(playlistId, nextPageToken);
    }

    // Retrieve the previous page of videos in the playlist.
    function previousPage() {
        requestVideoPlaylist(playlistId, prevPageToken);
    }

Z tad

https://developers.google.com/youtube/v3/docs/playlistItems/list

Ale nie mam bladego pojecia jak sie za to zabrac. Ktos cos?

1 odpowiedź

0 głosów
odpowiedź 1 sierpnia 2017 przez PoetaKodu Stary wyjadacz (10,990 p.)
wybrane 1 sierpnia 2017 przez Alex.Ironside
 
Najlepsza

Nie ten kod stąd wziąłeś, chodzi raczej o ten kod:
Tym poleceniem pobierasz itemy playlisty. Każdy item playlisty ma właściwość "id", która jest stringiem:

komentarz 1 sierpnia 2017 przez Alex.Ironside Stary wyjadacz (14,880 p.)
No dobra ale jak to wywolac i np console log?
komentarz 1 sierpnia 2017 przez Alex.Ironside Stary wyjadacz (14,880 p.)
Poza tym ten poprzedni kod tez trzeba dodac. Bez niego nie wie czym jest buildApiRequest
komentarz 1 sierpnia 2017 przez PoetaKodu Stary wyjadacz (10,990 p.)

No tak, to chyba oczywiste, ale do tego musisz najpierw załadować API, tu masz napisane jak to zrobić:

https://developers.google.com/youtube/v3/code_samples/javascript#authorize_a_request

Trochę ciężki orzech do zgryzienia bo musisz autoryzację przeprowadzić, swoje ID dostać itp.
Potem jak już to załadujesz to możesz zrobić np. tak:

var result = buildApiRequest('GET',
                '/youtube/v3/playlistItems',
                {'maxResults': '25',
                 'part': 'items,snippet,contentDetails',
                 'playlistId': 'PL12LRyfcS5ZZMNBGOtD2GeoRo_l9v51Rx'});
var items = result.items;
for(let itemIndex in items)
{
	console.log("Video name: " +  items[itemIndex].snippet.name + ", id: " + items[itemIndex].id); 
}

Nie wiem dokładnie co trzeba zrobić po otrzymaniu danego rezultatu przez buildApiRequest ale prawdopodobnie właśnie to wygląda tak jak to pokazałem.
Powinieneś najpierw skupić się, żeby API załadować, potem spróbuj tego kodu co Ci wysłałem.

1
komentarz 1 sierpnia 2017 przez Alex.Ironside Stary wyjadacz (14,880 p.)
edycja 1 sierpnia 2017 przez ScriptyChris

Dobra zrobie recznie. od 5h sie z tym mecze. Dzieki mimo wszystko ;)

Proszę o kulturalne wyrażanie się.Regulamin, pkt. II.1.B

komentarz 2 sierpnia 2017 przez niezalogowany

Zrobiło mi się szkoda twojego czasu. Łap:

Verico - Greater Barrie Chamber of Commerce 2014 Business Awards - -siixm2_zUI
Tyger Shark - Greater Barrie Chamber of Commerce 2014 Business Awards - VJdLZoKrzww
Tourism Barrie - Greater Barrie Chamber of Commerce 2014 Business Awards - AFw5NwckxQY
Williams - Greater Barrie Chamber of Commerce 2014 Business Awards - 7Wvflp4k3EU
Family TLC - Greater Barrie Chamber of Commerce 2014 Business Awards - QI_fInh5MMc
Telus - Greater Barrie Chamber of Commerce 2014 Business Awards - iASkrrAjLNA
Swirleez - Greater Barrie Chamber of Commerce 2014 Business Awards - s2kAfT2mIaw
Sip Soda - Greater Barrie Chamber of Commerce 2014 Business Awards - CXxh_iFgEQg
Suite Success - Greater Barrie Chamber of Commerce 2014 Business Awards - Al8OV8FF7-k
Signature Suites - Greater Barrie Chamber of Commerce 2014 Business Awards - ydIhQ2mYzsE
Ice Halo 02 - Greater Barrie Chamber of Commerce 2014 Business Awards - VKxDkNxAR1U
Concept of Motion - Greater Barrie Chamber of Commerce 2014 Business Awards - 0vhlGKkFhFg
Northern Protocol - Greater Barrie Chamber of Commerce 2014 Business Awards - _8PvyrWZEC8
English and Miller 02 - Greater Barrie Chamber of Commerce 2014 Business Awards - Tn_JECmFFWw
English and Miller 01 - Greater Barrie Chamber of Commerce 2014 Business Awards - KWjJQ2x8vfM
SalterPilon - Greater Barrie Chamber of Commerce 2014 Business Awards - p0pQKQ9dY2I
The Creative Space - Greater Barrie Chamber of Commerce 2014 Business Awards - SATFBeY7WF0
Pavliks.com - Greater Barrie Chamber of Commerce 2014 Business Awards - 6pnecGvWWQI
Cravings - Greater Barrie Chamber of Commerce 2014 Business Awards - vp0roVOQMNY
Sexton Mechanical - Greater Barrie Chamber of Commerce 2014 Business Awards - 6dewRcOsFNQ
Ice Halo 01 - Greater Barrie Chamber of Commerce 2014 Business Awards - KNhxe1K1KQo
GEEP - Greater Barrie Chamber of Commerce 2014 Business Awards - K-Tc_oDM5Ms
Napoleon Home Comfort - Greater Barrie Chamber of Commerce 2014 Business Awards - bpo8tC6xnmc
Apple A Day Naturopathic Walk-In Clinic - Greater Barrie Chamber of Commerce 2014 Business Awards - S66mNaodgWo
Shred North - Greater Barrie Chamber of Commerce 2014 Business Awards - xblkcyx_qHk
Brayden Longstaff - Greater Barrie Chamber of Commerce 2014 Business Awards - dbTlAEkhRkw
Image Dental Laboratories - IDL - Greater Barrie Chamber of Commerce 2014 Business Awards - Zkdw9UwarpU
Jebco - Greater Barrie Chamber of Commerce 2014 Business Awards - KzFdZ00mJkE
Eclectaccessaries - Greater Barrie Chamber of Commerce 2014 Business Awards - WKnetRpn4Yo
Georgian Detailing - Greater Barrie Chamber of Commerce 2014 Business Awards - nNTtFXXts9M
HGR Graham Partners - Greater Barrie Chamber of Commerce 2014 Business Awards - XgPLrq1muT8
Barrie Taxi - Greater Barrie Chamber of Commerce 2014 Business Awards - 4daKjKo_kdQ
Netgain SEO - Greater Barrie Chamber of Commerce 2014 Business Awards - qsVUAtcO4xI
Ann Green Yoga - Greater Barrie Chamber of Commerce 2014 Business Awards - 2MhQPxG04Ys
Busch Systems - Greater Barrie Chamber of Commerce 2014 Business Awards - SQYm5WZxPt8
Greater Barrie Chamber of Commerce 2014 Santa Claus Parade - wzzj7VRYmFU

 

komentarz 2 sierpnia 2017 przez Alex.Ironside Stary wyjadacz (14,880 p.)
Nie o to mi chodzilo ale dzieki xD
komentarz 2 sierpnia 2017 przez niezalogowany
Sugerowałem się kodem z pierwszego postu. Przynajmniej próbowałem pomóc, mam nadzieję, że dzięki tej próbie będę postrzegany jako osoba z dobrym i wrażliwym serduszkiem.
komentarz 2 sierpnia 2017 przez Alex.Ironside Stary wyjadacz (14,880 p.)
Przeciez powiedzialem ze dziekuje :(

Podobne pytania

0 głosów
1 odpowiedź 185 wizyt
pytanie zadane 1 sierpnia 2017 w JavaScript przez Alex.Ironside Stary wyjadacz (14,880 p.)
0 głosów
0 odpowiedzi 148 wizyt
pytanie zadane 12 stycznia 2017 w Android, Swift, Symbian przez kacperdyba Gaduła (3,290 p.)
+1 głos
0 odpowiedzi 125 wizyt
pytanie zadane 29 marca 2022 w JavaScript przez zerakot Obywatel (1,870 p.)

92,453 zapytań

141,262 odpowiedzi

319,087 komentarzy

61,854 pasjonatów

Motyw:

Akcja Pajacyk

Pajacyk od wielu lat dożywia dzieci. Pomóż klikając w zielony brzuszek na stronie. Dziękujemy! ♡

Oto polecana książka warta uwagi.
Pełną listę książek znajdziesz tutaj.

Akademia Sekuraka

Akademia Sekuraka 2024 zapewnia dostęp do minimum 15 szkoleń online z bezpieczeństwa IT oraz dostęp także do materiałów z edycji Sekurak Academy z roku 2023!

Przy zakupie możecie skorzystać z kodu: pasja-akademia - użyjcie go w koszyku, a uzyskacie rabat -30% na bilety w wersji "Standard"! Więcej informacji na temat akademii 2024 znajdziecie tutaj. Dziękujemy ekipie Sekuraka za taką fajną zniżkę dla wszystkich Pasjonatów!

Akademia Sekuraka

Niedawno wystartował dodruk tej świetnej, rozchwytywanej książki (około 940 stron). Mamy dla Was kod: pasja (wpiszcie go w koszyku), dzięki któremu otrzymujemy 10% zniżki - dziękujemy zaprzyjaźnionej ekipie Sekuraka za taki bonus dla Pasjonatów! Książka to pierwszy tom z serii o ITsec, który łagodnie wprowadzi w świat bezpieczeństwa IT każdą osobę - warto, polecamy!

...