Link to home
Create AccountLog in
Avatar of Wayne Barron
Wayne BarronFlag for United States of America

asked on

YouTube API get the Video Tags -

I am trying to get the "tags" and I am having a hard time doing it.
This is the last item that I have to do, to complete this part of the project.

JSON Sample
 "items": [
   "id": "tyGHrfDGTR",
   "snippet": {
    "title": "This is the title",
    "tags": [

Open in new window


Class VidList
    Public Property Items() As List(Of VidItem)
End Class

Class VidItem
    Public Property Id() As String
    Public Property Snippet() As VidSnippet
End Class

Class VidSnippet
    Public Property Title() As String
    Public Property Description() As String
    Public Property tags() As String
End Class

For Each [item] In playList.Items

Open in new window

(Above code assisted by -saige- )

With the [] and nothing after it, I am lost on how to get the tags values returned back.

Avatar of it_saige
Flag of United States of America image

Your tags property should be a list of string or a string array; e.g. -
Public Property tags() As List(Of String)
' OR
Public Property tags() As String()

Open in new window

Proof of concept -
Module Module1
    Const json = "{" _
& """items"": [" _
& "{""id"" : ""tyGHrfDGTR"", " _
& """snippet"": {""title"": ""This is the title"", " _
& """tags"": [""one"", ""two"", ""three"", ""four"", ""five""]}}]}"

    Sub Main()
        Dim videoList = Newtonsoft.Json.JsonConvert.DeserializeObject(Of VideoList)(json)
        Console.WriteLine("Items: ")
        For Each videoItem In videoList.Items
            Console.WriteLine(vbTab & "ID: " & videoItem.ID)
            Console.WriteLine(vbTab & "Snippet:")
            Console.WriteLine(vbTab & vbTab & "Title: " & videoItem.Snippet.Title)
            Console.WriteLine(vbTab & vbTab & "Description: " & videoItem.Snippet.Description)
            Console.WriteLine(vbTab & vbTab & "Tags:")
            For Each tag In videoItem.Snippet.Tags
                Console.WriteLine(vbTab & vbTab & vbTab & tag)
    End Sub
End Module

Class VideoList
    Public Property Items() As List(Of VideoItem)
End Class

Class VideoItem
    Public Property ID() As String
    Public Property Snippet() As VideoSnippet
End Class

Class VideoSnippet
    Public Property Title() As String
    Public Property Description() As String
    Public Property Tags() As List(Of String)
End Class

Open in new window

Produces the following output -User generated image
Avatar of Wayne Barron


Hey, -saige-
Hum, that is going to be difficult to add to a database.
Unless I insert everything into the table and then come back and make another request and then update the database, add in these tags.
Unless you can think of a better way.
I found out that we are limited to 1 million requests per day.
Would this "Loop" count for 1 request, or 5 requests in this example?
Avatar of it_saige
Flag of United States of America image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
The comma-delimited list will work perfectly.

What do you mean by this?
>> I don't understand why you have to use one insert
Just an off hand question.  In general, most db inserts insert separate records into separate rows rather than trying to insert everything at once.  You can always use transactions if you want to ensure that the entire record set gets added but trying to jam everything here into a single row (your original playlist included) just muddy's up the water.

I have 3 tables.

The Tags
They are inserted into the Videos [Tags] Column.
Thanks again, -saige-
I am slowly but surely learning how to use this the way I need it.

Have a rockin rest of the week.