Solved

YouTube API get the Video Tags - vb.net

Posted on 2017-04-14
7
74 Views
Last Modified: 2017-04-17
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": [
     "one",
     "two",
     "three",
     "four",
     "five"
    ]
   }
  }
 ]
}

Open in new window


VB.NET Code

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
            Response.Write(item.Snippet.tags)
next

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.

Thanks
Carrzkiss
0
Comment
Question by:Wayne Barron
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 34

Expert Comment

by:it_saige
ID: 42095410
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)
            Next
        Next
        Console.ReadLine()
    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 -Capture.PNG
-saige-
0
 
LVL 31

Author Comment

by:Wayne Barron
ID: 42095570
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.
Also.
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?
0
 
LVL 34

Accepted Solution

by:
it_saige earned 500 total points
ID: 42095589
I would imagine that it is one request as you get your data back as one request result.  As for the db, you could insert the tags as a comma-delimited list (athough with the cost of disk space being so long and the request size being so small, I don't understand why you have to use one insert), unless of course, you are limited on your input requests.

As for constructing the comma-delimited list:
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: " & String.Join(",", videoItem.Snippet.Tags))
        Next
        Console.ReadLine()
    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

Now produces the following output -Capture.PNGBe aware, however, of size limitations imposed on varchar(MAX) and that if your string elements contain comma's this will be split when you try to parse the field into it's separate elements.

-saige-
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 31

Author Comment

by:Wayne Barron
ID: 42095610
The comma-delimited list will work perfectly.

What do you mean by this?
>> I don't understand why you have to use one insert
0
 
LVL 34

Expert Comment

by:it_saige
ID: 42095616
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.

-saige-
0
 
LVL 31

Author Comment

by:Wayne Barron
ID: 42095649
OK.
I have 3 tables.
Users
List
Videos

The Tags
They are inserted into the Videos [Tags] Column.
0
 
LVL 31

Author Closing Comment

by:Wayne Barron
ID: 42095992
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.
Wayne
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question