|
#1
|
elite*gold: 12
Join Date: Aug 2011
Posts: 455
Received Thanks: 418
|
[C# Tutorial]How to post comment to YouTube with Form Application
Hello everybody. I'm gonna show you how to post comment to youtube videos only with a button. First we must register an api to do it. So please go to:
Quote:
You will see a screen like that :
Please click to that button to create a new API for Google.
If you clicked to "Create Project" button, Google will make it.
You will see 4 options these named : Overview, Services, Team and API Access
Please enter to API Access tab:
Then click to "Create an OAuth 2.0 cliend ID" button.
Fill up all forms like that(You can put the name what you want) :
Then click to "Create client ID". After that, go to API Access again:
Please open a new notepad and save them :
Quote:
App Name : you commenter
Dev Key : xxxx
|
Now open Visual Studio and create a new form application.
Prepare your design. Because in programming, design is first:
(mm... it is enough xD)
Now we will add some references to the project. First download these libraries:
Quote:
and add these two libraries to your project(I won't do explain that how to add library to a project as reference).
and add this code start of Form.cs:
HTML Code:
using Google.YouTube;
Now create button_click event and add these:
PHP Code:
YouTubeRequestSettings settings = new YouTubeRequestSettings("app name", "dev key", textBox1.Text, textBox2.Text);
YouTubeRequest request = new YouTubeRequest(settings);
We prepared our request. We will use it to post comment. textBox1.Text is google username of user and textBox2.Text is password of the account.
Now let's prepare our objects. Whare are they? Video and Comment.
PHP Code:
Uri videoUrl = new Uri("http://gdata.youtube.com/feeds/api/videos/" + textBox3.Text);
Video video = request.Retrieve<Video>(videoUrl);
With these codes, we got our video object. textBox3.Text is our video ID. So it is red marked in following:
Quote:
|
youtube.com/watch?v=hO2wA0Te0wM
|
Last one is Comment. It is just like that :
PHP Code:
Comment comment = new Comment();
comment.Content = richTextBox1.Text;
Now let's start to post comment :
PHP Code:
request.AddComment(video, comment);
And press F5 to start project :
Result :
Done !
|
|
|