I am using ASPJson for working with ASP and JSON (it used to be hosted here a while ago http://www.aspjson.com/ but that site is no longer live, but the code I got from that site is here: https://pastebin.com/LJzikNAT)
This is my call to Youtube - example:
https://www.googleapis.com/youtube/v3/search?part=id&q=london&type=video&key=[my_key]
That returns this JSON data:
{
"kind": "youtube#searchListResponse",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/o9DTjpevDXudxmhkLef6i-kAnRE\"",
"nextPageToken": "CAUQAA",
"regionCode": "GB",
"pageInfo": {
"totalResults": 1000000,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/Qq093B1iIdU7htjV5jYf2Erqxgk\"",
"id": {
"kind": "youtube#video",
"videoId": "5DniDm9epIY"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/gbHSPn7IT-2OJG19vQZzKKTbG1s\"",
"id": {
"kind": "youtube#video",
"videoId": "Zlu542Tx8Fc"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/KQSQBNAk2ArZd_XrpDOIfiMT0XM\"",
"id": {
"kind": "youtube#video",
"videoId": "2tufxwCyrmE"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/wrbmiGkrH9v_QvtNpoIurXH9YQc\"",
"id": {
"kind": "youtube#video",
"videoId": "1XU8AOZ0Inw"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/2sdAsprKoDKIt8mNVYd8prR8uVA\"",
"id": {
"kind": "youtube#video",
"videoId": "vUO6kYLb6As"
}
}
]
}
This is my ASP code to try and loop through the results:
<!--#INCLUDE file="../dist/asp/c.asp" -->
<!--#INCLUDE file="../dist/asp/aspJSON.asp" -->
<%
my_api = "my_key"
sendstring1 = "https://www.googleapis.com/youtube/v3/search?part=id&q=chester&type=video&key="&my_api&""
Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
objXML.Open "GET", sendstring1 , false
objXML.Send()
BackFromGoogle1 = objXML.responseText
Set oJSON = New aspJSON
oJSON.loadJSON(BackFromGoogle1)
For Each result In oJSON.data("items")
Set this = oJSON.data("items").item(thingy)
var_id = this.item("id").item("videoId")
embed_code = "<iframe width='800' height='450' src='https://www.youtube.com/embed/"&var_id&"?rel=0&wmode=opaque' frameborder='0' allowfullscreen></iframe>"
response.write embed_code
Next
%>
The trouble is that as I loop through it, the ID returned in the var_id
variable is always 5DniDm9epIY
, which is the ID of the first video - it doesn't seem to be changing each time through the loop, and I'm not sure why?
The var_id
is displayed 5 times, so the code can see that there are 5 notes in the "items" collection, but it doesn't appear to go to the next node each time through the loop.