[WebDNA] YouTube Query Code Sample
This WebDNA talk-list message is from 2013
It keeps the original formatting.
numero = 110523
interpreted = N
texte = --047d7bf0c0465c0f0704e2c913a2Content-Type: text/plain; charset=ISO-8859-1Hi, here's how to connect to youTube to do a search and return xml results.These are not athenticated calls.Parameters:https://developers.google.com/youtube/2.0/developers_guide_protocol_api_query_parameters#qspMake the Call:[text]theSearchString=[url]"[/url]the+tragically+hip[url]"[/url][/text][text]MyResult=[!][/!][TCPConnect host=gdata.youtube.com][TCPSend skipheader=T]GET/feeds/api/videos?q=[theSearchString]&orderby=relevance&start-index=1&max-results=50&v=2HTTP/1.0[UnURL]%0D%0A[/Unurl]Host: gdata.youtube.com[UnURL]%0D%0A%0D%0A[/UnURL][/TCPSend][/TCPConnect][/text][xmlparse var=xml_var1][MyResult][/xmlparse][xmlnodes ref=xml_var1&path=named:feed&name=openSearch:totalResults]
Total Videos=[value]
[/xmlnodes]I got a result of:*Total Videos*=76214from the "MyResult" variable you get the entire xml which can be decipheredhere:https://developers.google.com/youtube/2.0/developers_guide_protocol_understanding_video_feeds#Understanding_Video_EntriesYoutube limits the results to 1000 videos, but say you wanted to grab thatinformation of all 1000 videos, you might start off with something likethis.Note: you can do this with one call - but i have shown how to do it withtwo:I've limited this to pull 100 videos, but just change the 100 to 1000.From here, you dynamically generate field names and write to a database.There are different ways to parse the xml depending upon your needs.[showif [theSearchTotal]>100] [text]theSearchTotal=101[/text][/showif]This code in action here:http://dev.tenplusone.com/youTubeEngine/testPull.html----code starts here----[text]showTracking=1[/text][text]theSearchString=[url]"[/url]the+tragically+hip[url]"[/url][/text][text]MyResult=[!][/!][TCPConnect host=gdata.youtube.com][TCPSend skipheader=T]GET/feeds/api/videos?q=[theSearchString]&orderby=relevance&start-index=1&max-results=50&v=2HTTP/1.0[UnURL]%0D%0A[/Unurl]Host: gdata.youtube.com[UnURL]%0D%0A%0D%0A[/UnURL][/TCPSend][/TCPConnect][/text][xmlparse var=xml_var1][MyResult][/xmlparse][xmlnodes ref=xml_var1&path=named:feed&name=openSearch:totalResults]
Total Videos=[value]
[text]theSearchTotal=[value][/text][/xmlnodes][hideif [theSearchTotal]=0][showif [theSearchTotal]>100] [text]theSearchTotal=101[/text][/showif][loop start=1&end=[theSearchTotal]&advance=50]
*[index][text]MyResult2=[!][/!][TCPConnect host=gdata.youtube.com][TCPSend skipheader=T]GET/feeds/api/videos?q=[theSearchString]&orderby=relevance&start-index=[index]&max-results=50&v=2HTTP/1.0[UnURL]%0D%0A[/Unurl]Host: gdata.youtube.com[UnURL]%0D%0A%0D%0A[/UnURL][/TCPSend][/TCPConnect][/text][xmlparse var=xml_var2][MyResult2][/xmlparse]
------------------------------------------------
[loop start=1&end=50]
**[index][xmlnodes ref=xml_var2&path=named:feed/entry([index])] [showif [showTracking]=1] -
[name]=[value]
[/showif][xmlnodeattributes] [showif [showTracking]=1] --
[name]=[value]
[/showif][/xmlnodeattributes] [xmlnodes] [showif [showTracking]=1] ---
[name]=[value]
[/showif] [xmlnodeattributes] [showif [showTracking]=1] ----
[name]=[value]
[/showif] [/xmlnodeattributes] [xmlnodes][/xmlnodes][/xmlnodes][/xmlnodes]
------------------------------------------------------------------------------------------------------------------------
[/loop][/loop]--047d7bf0c0465c0f0704e2c913a2Content-Type: text/html; charset=ISO-8859-1Content-Transfer-Encoding: quoted-printable
Make the Call:
[text]theSearchString=3D[url]"[/url]t=he+tragically+hip[url]"[/url][/text]
[text]MyResult=3D[!]
[/=!][TCPConnect host=3D
gdata.youtube.com=][TCPSend skipheader=3DT]GET /feeds/api/videos?q=3D[theSearchString]&am=p;orderby=3Drelevance&start-index=3D1&max-results=3D50&v=3D2 HT=TP/1.0[UnURL]%0D%0A[/Unurl]Host:
gdata=.youtube.com[UnURL]%0D%0A%0D%0A[/UnURL][/TCPSend]
[/TCPConnect][/text]
[xmlparse var=3Dxml_var1][MyResult][/xmlparse]<=br>
[xmlnodes ref=3Dxml_var1&path=3Dnamed:feed&name=3DopenSearch=:totalResults]
<b>Total Videos</b>=3D[value]<br />
=[/xmlnodes]
I got a result of:Total Videos=3D76214
<=div>from the "MyResult" variable you get the entire xml which can= be deciphered here:
https://developers.google.com/youtube/2.0/developers_guide_protocol_un=derstanding_video_feeds#Understanding_Video_Entries
Youtube limits the results to 1000 videos, bu=t say you wanted to grab that information of all 1000 videos, you might sta=rt off with something like this.
Note: you can do this with =one call - but i have shown how to do it with two:
I've limited this to pull 100 videos, but just change th=e 100 to 1000.
From here, you dynamically generate field name=s and write to a database.
There are different ways to parse =the xml depending upon your needs.
----code starts here----
[text]showTracking=3D1[/text]
[text]theSearchString=3D[url]"[/url=]the+tragically+hip[url]"[/url][/text]
[text]MyResult=3D[!]
=[/!][TCPConnect host=3Dgdata.youtube.c=om][TCPSend skipheader=3DT]GET /feeds/api/videos?q=3D[theSearchString]&=amp;orderby=3Drelevance&start-index=3D1&max-results=3D50&v=3D2 =HTTP/1.0[UnURL]%0D%0A[/Unurl]Host: gda=ta.youtube.com[UnURL]%0D%0A%0D%0A[/UnURL][/TCPSend]
[/TCPConnect][/text]
[xmlparse var=3Dxml_var1][MyResult][/xmlparse]<=br>
[xmlnodes ref=3Dxml_var1&path=3Dnamed:feed&name=3DopenSe=arch:totalResults]
<b>Total Videos</b>=3D[value]<br />=
[text]theSearchTotal=3D[value][/text]
[/xmlnodes]
[hideif [theSearchTotal]=3D0]
[showif [theSearch=Total]>100]
=A0=A0=A0 [text]theSearchTotal=3D101[/text]
[/showif]<=br>
[loop start=3D1&end=3D[theSearchTotal]&advance=3D50]
<=b>*[index]</b><br />
[text]MyResult2=3D[!]
[/!][TCPConnect host=3Dgdata.youtube.com][TCPSend skipheader=3DT]GET /feeds/api/=videos?q=3D[theSearchString]&orderby=3Drelevance&start-index=3D[ind=ex]&max-results=3D50&v=3D2 HTTP/1.0[UnURL]%0D%0A[/Unurl]Host: gdata.youtube.com[UnURL]%0D%0A%0D%0A[/U=nURL][/TCPSend]
[/TCPConnect][/text]
[xmlparse var=3Dxml_var2][MyResult2][/xmlparse]=
<br />------------------------------------------------<br =/>
[loop start=3D1&end=3D50]
<b>**[index]</b>&=lt;br />
[xmlnodes ref=3Dxml_var2&path=3Dnamed:feed/entry([index])]
<=br>=A0=A0=A0 [showif [showTracking]=3D1]
=A0=A0=A0 - <b>[name]<=/b>=3D[value]<br />
=A0=A0=A0 [/showif]
[xmlnodeattributes]<=br>=A0=A0=A0 [showif [showTracking]=3D1]
=A0=A0=A0 -- <b>[name]</b>=3D[value]<br />
=A0=A0=A0 [=/showif]
[/xmlnodeattributes]
=A0=A0=A0 [xmlnodes]
=A0=A0=A0==A0=A0=A0=A0 [showif [showTracking]=3D1]
=A0=A0=A0=A0=A0=A0=A0 --- <b=>[name]</b>=3D[value]<br />
=A0=A0=A0=A0=A0=A0=A0 [/showi=f]
=A0=A0=A0=A0=A0=A0=A0
=A0=A0=A0=A0=A0=A0=A0 [xmlnodeattributes]
=A0==A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 [showif [showTracking]=3D1]
=A0=A0=A0=A0==A0=A0=A0=A0=A0=A0=A0 ---- <b>[name]</b>=3D[value]<br /><=br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 [/showif]
=A0=A0=A0=A0=A0=A0=A0 [/x=mlnodeattributes]
=A0=A0=A0 [xmlnodes]
=A0=A0=A0
[/xmlnodes]
[/xmlnodes]
[/xmlnodes]
<br />----=---------------------------------------------------------------------------=-----------------------------------------<br /><br />
[/loop=]
[/loop]
--047d7bf0c0465c0f0704e2c913a2--
Associated Messages, from the most recent to the oldest:Youtube limits the results to 1000 videos, bu=t say you wanted to grab that information of all 1000 videos, you might sta=rt off with something like this.
I've limited this to pull 100 videos, but just change th=e 100 to 1000.
From here, you dynamically generate field name=s and write to a database.
There are different ways to parse =the xml depending upon your needs.
The WebDNA community talk-list is the best place to get some help: several hundred extremely proficient programmers with an excellent knowledge of WebDNA and an excellent spirit will deliver all the tips and tricks you can imagine...