Hey guys,
Here's the sources I've used for certain functions. This are only the functions, not whole copy and pastable codes. (The most of it is c&pable though).
If you don't like my coding style, not my problem. Nothing of this is objective because I'm used to C++. Due to YouTube's API not being available in C/C++ though, I made this in VB.NET, because I don't like C#.
Preparing
- First off you need the YouTube GData Libraries:
Download and install the YouTube API Libraries:

- Then obtain an API key here using a Google Account:

- Start a new VB.NET Project and link to Google.GData.Client.dll, Google.GData.Extensions.dll, Google.GData.YouTube.dll
You can find them here:
Code:
C:\Program Files (x86)\Google\Google YouTube SDK for .NET\Samples
(or where ever you installed the SDK. Note: Though youtube says you can find them in the "Redist" Folder, this particular folder doesn't contain all necessary Libraries.)
- You will need the following imports:
Code:
Imports Google.GData.Client
Imports Google.GData.Extensions
Imports Google.GData.YouTube
Imports Google.GData.YouTube.YouTubeService
Imports Google.GData.Extensions.MediaRss
Imports Google.YouTube
Imports System.Management
Imports System.Net
Imports System.IO
- Now you're ready to do some coding!
Snippets
First you need to authenticate yourself with the API key and an account:
Code:
Dim settings As YouTubeRequestSettings
Dim request As YouTubeRequest
settings = New YouTubeRequestSettings(APPLICATION_NAME, DEVELOPER_KEY, ACC_USERNAME, ACC_PASSWORD)
request = New YouTubeRequest(settings)
APPLICATION_NAME: The app name you've chosen in google developer dashboard
DEVELOPER_KEY: Your api/dev key for the particular app you defined before
ACC_USERNAME + ACC_PASSWORD: Obvious
--
Then, you need to define a Video:
Code:
Dim VideoFeedUri As Uri
Dim dVideo As Video
VideoFeedUri = New Uri("http://gdata.youtube.com/feeds/api/videos/" + dVideoID)
dVideo = request.Retrieve(Of Video)(VideoFeedUri)
dVideoID = Your video ID (the thing behind watch?v= WITHOUT special addons like &feature=related
--
Now, once you're authenticated and you've defined a video you can do some cool stuff:
Like Video
Code:
dVideo.Rating = 5
request.Insert(dVideo.RatingsUri, dVideo)
Dislike Video
Code:
dVideo.Rating = 1
request.Insert(dVideo.RatingsUri, dVideo)
Subscribe to uploader of video
Code:
Dim s As Subscription = New Subscription
s.Type = SubscriptionEntry.SubscriptionType.channel
s.UserName = dVideo.Uploader
request.Insert(New Uri(YouTubeQuery.CreateSubscriptionUri("SUBSCRIBER_ACC")), s)
SUBSCRIBER_ACC: The account which subscribes to the channel. Has to be the account you authenticated with.
Note: You can basically subscribe to any channel by just adjusting s.UserName.
Add a video as favorite
Code:
Dim videoEntryUrl As String = "http://gdata.youtube.com/feeds/api/videos/" + dVideoID
Dim service As YouTubeService = request.Service
Dim videoEntry As YouTubeEntry = service.Get(videoEntryUrl)
Dim feedUrl As String = "http://gdata.youtube.com/feeds/api/users/default/favorites"
service.Insert(New Uri(feedUrl), videoEntry)
Adding a comment
Code:
Dim c As Comment = New Comment()
c.Content = "Comment Content"
request.AddComment(dVideo, c)
Flagging a video
Code:
Dim c As Complaint = New Complaint
c.Type = ComplaintEntry.ComplaintType.DANGEROUS
c.Content = "This video is dangerous!! My son watched it, this should be deleted"
request.Insert(dVideo.ComplaintUri, c)
Note: Other Flag types are: ComplaintEntry.ComplaintType.HATE, ComplaintEntry.ComplaintType.PORN, ComplaintEntry.ComplaintType.RIGHTS, ComplaintEntry.ComplaintType.SPAM, ComplaintEntry.ComplaintType.VIOLENCE
Sending message (video recommendation -> no send limit per account)
Code:
Dim friedsInbox As String = "http://gdata.youtube.com/feeds/api/users/" + id + "/inbox"
Dim newMessage As MessageEntry = New MessageEntry
Dim videoEntry As YouTubeEntry = request.Service.Get("http://gdata.youtube.com/feeds/api/videos/" + dVideoID)
newMessage.Title.Text = "Message Subject / Title"
newMessage.Summary.Text = "Message Text"
newMessage.Id = videoEntry.Id
request.Service.Insert(New Uri(friedsInbox), newMessage)
id = account to receive message
Adding contacts
Code:
Dim feedUrl As String = "http://gdata.youtube.com/feeds/api/users/default/contacts"
Dim newFriend As FriendsEntry = New FriendsEntry
newFriend.UserName = "FriendToAdd"
newFriend.Categories.Add(New AtomCategory("Friend Category", YouTubeNameTable.FriendsCategorySchema))
request.Service.Insert(New Uri(feedUrl), newFriend)
Now have fun !