Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

[VB.NET] YouTube API Bot Snippets [DIS]LIKE/SUB/FAV/COMMENT/FLAG/MESSAGE/ADD CONTACT

Hey guys,

you may know my Bot https://hackforums.net/showthread.php?tid=1544197 which is based on youtube API. I honestly do not have the time to update this frequently and I don't want to.

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: http://code.google.com/p/google-gdata/downloads/list
- Then obtain an API key here using a Google Account: http://code.google.com/apis/youtube/dashboard/
- 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)

--

Things yet not being able to do via API:
- Comment rating (thumbs up/down)
- Sending "real" private messages (while video recommendation messages actually do the same job without the annoying limit ;))
- Boosting views obviously ;)

Now have fun 🤝

A bit more is still coming.

Credits: Google

WHEN YOU ARE LEECHING THIS, PLEASE AT LEAST REFER TO ME (MAXN/PWHOAM)
Thanks for making this bro. Is there an add as friend code?
Just added it. 25 characters
Nice one!! 🤝
:D:D:D
Thanks a lot for this and why am I getting these errors? "I am new to the api."
[Image: b2e65e7edc2dc9af055aed5c4ad8fb22.png]
(Aug 4, 2011 02:27 PM)PURP Wrote:  Thanks a lot for this and why am I getting these errors? "I am new to the api."
[Image: b2e65e7edc2dc9af055aed5c4ad8fb22.png]

Sorry pal, fixed this. This was actually my function to get the current account from an account file.

Look at the first post. "getAccount(line)" is the account which subscribes, which has to be the account you authenticated with.
Thank you but now when I try to debug it, it gives me this error? It doesn't point to anything that just pops up.
[Image: e7e58c45bf3565deca45da938134768e.png]
(Aug 4, 2011 02:44 PM)PURP Wrote:  Thank you but now when I try to debug it, it gives me this error? It doesn't point to anything that just pops up.
[Image: e7e58c45bf3565deca45da938134768e.png]

http://stackoverflow.com/questions/28668...details-th
It wont load when I have these 3 lines.
PHP Code

<?php 
'Dim videoEntryUrl As String = "http://gdata.youtube.com/feeds/api/videos/" + TextBox5.Text
    '
Dim service As YouTubeService = request.Service
    
'Dim videoEntry As YouTubeEntry = Service.Get(videoEntryUrl) 
Depends where these lines are...
Working great here, thanks
When i iterate through my accounts to "like" a particular video, it fails on the 7th account because the server seems to reject the connection, how do you deal with this?
sweet post bro will was very helpful. I really like the post making my bot just now :)
I've been trying to get the message box API working since yesterday. The example they posted on the developer network doesn't work. Do you know how to do this? Basically to list all the messages in a user inbox.
[Image: tqE7M8d.png]
Nice job, get ready to see marketplace bombed with more youtube bots though lol.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by SIM-5432905Nov 16, 2023 04:06 PM 8 287 Nov 16, 2023 04:06 PM
Last Post: Hackers
by DaquanggJun 8, 2023 10:23 PM 9 166 Jun 8, 2023 10:23 PM
Last Post: Kalvaxas
[Python] by streetlawkarmaOct 12, 2018 11:53 AM 1 169 Oct 12, 2018 11:53 AM
Last Post: m0noxide