[Visual Baisc] Youtube API Bot Snippets

11/11/2011 19:08 Dispicable#1
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: [Only registered and activated users can see links. Click Here To Register...]
- Then obtain an API key here using a Google Account: [Only registered and activated users can see links. Click Here To Register...]
- 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 !
11/11/2011 19:20 l1ght ##2
vllt mal Credits geben, von wem du es c&p hast -.- die snippets sind von maxn ( mate von mir )
11/11/2011 19:51 Kraizy​#3
Quote:
Originally Posted by l1ght # View Post
die snippets sind von maxn ( mate von mir )
Kannst du das auch beweisen?^^
Es gibt sicher nicht nur ein Programm, welches die YouTube API benutzt, und die Funktionen sind bestimmt nicht bei jedem komplett anders, wie denn auch?
11/13/2011 19:33 Yakiyo#4
Quote:
Originally Posted by xKraizy View Post
Kannst du das auch beweisen?^^
Es gibt sicher nicht nur ein Programm, welches die YouTube API benutzt, und die Funktionen sind bestimmt nicht bei jedem komplett anders, wie denn auch?
Ja, es ist von diesem Hampelmann.
Ich habe diese Snippets ja selbst gepostet, hab es halt sozusagen übersetzt.
11/13/2011 20:22 Kraizy​#5
Ich versteh nicht ganz, warum es hier um Maxn geht. Vielleicht habt ihr beiden ja diese Funktionen von ihm, d.h. doch aber nicht, dass er sie "erfunden" hat, denn so ist halt der Aufbau, wenn man z.B. ein Video liken will..
Hier gibts den Aufbau von allen Funktionen: [Only registered and activated users can see links. Click Here To Register...] welche man dann eben auf VB.NET übertragen muss, was nicht gerade schwer ist..und am Ende hat jedes Programm den selben Code..