Click here to Skip to main content
15,867,330 members
Articles / Web Development / ASP.NET
Article

Vimeo API in ASP.NET using C#

Rate me:
Please Sign up or sign in to vote.
3.00/5 (6 votes)
30 Jan 2012CPOL2 min read 71.4K   3.1K   9   25
Use .NET C# language to access the API of Vimeo

Introduction

Vimeo is a video hosting service to share videos. It has a well defined API to access it's functionality from a third party application. This article describes a step by step procedure to use the API from an ASP.NET application.

Download & Use of Code

Please download the code attached with this article. Host the application in your local IIS. Set the application name as "VimeoAPI"

Get Started

You have to register with Vimeo first. After successful login to the website, click here to add an application. Set the callback URL to "http://localhost/VimeoAPI/CallbackFromAuthSubRequestVimeo.aspx" while creating the application. After creating the application, request for the upload access. This may take some time. Once you get the approval, you are ready to go.

In the Vimeo application page, you will find "Consumer Key" and "Consumer Secret". Don't share this code with anyone. These are the keys to access your Vimeo account. Configure your web.config file to set these values to the keys "consumerKey" & "consumerSecret".

Generate OAuthToken & OAuthSecret

Follow this procedure to generate your OAuthToken & OAuthSecret. This is an onetime job. You can use those keys the rest of your life once created.

  1. Open the hosted website using Visual Studio. Set "GetUnauthorizedRequestToken.aspx" as start up page and run the website without debugging (Ctrl+F5). This will give you a temporary OAuthToken & OAuthSecret. Write these values in "AproveAccess.aspx.cs" and "GetOAuthToken.aspx" files in places of "Your OAuth Token" & "Your OAuth Secret".
  2. Set "AproveAccess.aspx" page as start up page and run the website without debugging (Ctrl+F5) again. This will redirect you to Vimeo to login and approve access for your application. Click on the "Access" button. This will redirect you to "http://localhost/VimeoAPI/CallbackFromAuthSubRequestVimeo.aspx" page where you will find "OAuthVerifier" code. Write this code in "GetOAuthToken.aspx" page in place of "Your OAuth Verifier".
  3. Now set "GetOAuthToken.aspx" page as start up page and run the website. This will give you the final OAuthToken & OAuthSecret. Configure your web.config file to put these values to the keys "oauthToken" & "oauthSecret".

Upload a Video

Once you have "OAuthToken" and "OAuthSecret" in hand, you are ready to access the API to upload & update videos. There is one API method called "VimeoAPI.UploadVideo" to upload a video. This method takes the following as parameters

  • Physical file path of the video
  • Title
  • Description
  • Tags separated by comma

This method is used in "UploadVideoInVimeo.aspx.cs" page as

C++
protected void btnUpload_Click(object sender, EventArgs e)
    {
        string fullPath = string.Empty;
        try
        {
            if (fuVideoFile.HasFile)
            {
                fullPath = Server.MapPath("~/FileStorage");
                fullPath = fullPath + "\\" + fuVideoFile.FileName;
                fuVideoFile.SaveAs(fullPath);
                if (File.Exists(fullPath))
                {
                    VideoUploadTicket videoTicket = VimeoNET.VimeoAPI.UploadVideo(fullPath, txtDescription.Text, txtDescription.Text, txtTags.Text, false);
                    if (videoTicket != null && videoTicket.VideoId != string.Empty)
                    {
                        Response.Write("<span style='color:red;'>Video Uploaded Successfully</span>");
                    }
                }
            }
        }
        catch (Exception ex)
        {
            string message = string.Empty;
            while (ex != null)
            {
                if (message == string.Empty)
                {
                    message = ex.Message;
                }
                else
                {
                    message = message + Environment.NewLine + ex.Message;
                }
                ex = ex.InnerException;
            }
            Response.Write(message);
        }
    } 

Update a Video

There is one method called "VimeoAPI.UpdateVideo" to update a video. "UpdateVideo.aspx.cs" file uses the following code

C++
protected void btnUpdate_Click(object sender, EventArgs e)
    {
        try
        {
            if (txtVideoId.Text != string.Empty)
            {
                if (VimeoAPI.UpdateVideo(txtVideoId.Text, txtTitle.Text, txtDescription.Text, txtTags.Text))
                {
                    Response.Write("<span style='color:red;'>Video Updated Successfully</span>");
                }
            }
            else
            {
                Response.Write("<font style='color:red;clear:both;'>Video Id is not provided</font>");
            }
        }
        catch (Exception ex)
        {
            string message = string.Empty;
            while (ex != null)
            {
                if (message == string.Empty)
                {
                    message = ex.Message;
                }
                else
                {
                    message = message + Environment.NewLine + ex.Message;
                }
                ex = ex.InnerException;
            }
            Response.Write("<font style='color:red;clear:both;'>"+message+"</font>");
        }
    }

Conclusion

This the first article on Vimeo API using .NET Code. This article covers the upload and update functionality of the API. My upcoming articles will cover the rest of the functionality. Hope this helps.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead Ominto Inc
United Arab Emirates United Arab Emirates
I am Bachelor in CSE from Khulna University of Engineering & Technology,Bangladesh. I have more than 11 years experience in software design & development, data analysis & modeling, project management and currently working in a software company in Dubai,UAE as a Lead Software Engineer. I am MCAD(Microsoft Certified Application Developer) certified since 2005. Please feel free to contact with me at nill_akash_7@yahoo.com.


Comments and Discussions

 
QuestionVimeo Upload Video Files 'GetUnauthorizedRequestToken.aspx' Run Getting Error Pin
Member 1481957424-Jun-20 23:12
Member 1481957424-Jun-20 23:12 
QuestionconsumerKey, consumerSecret not found Pin
Member 146461353-Jun-20 6:36
Member 146461353-Jun-20 6:36 
Questionerror GetUnauthorizedRequestToken.aspx Pin
Member 1227539719-Jan-16 23:37
Member 1227539719-Jan-16 23:37 
QuestionASP.Net Vimeo Upload Pin
aahista10-Dec-15 3:07
aahista10-Dec-15 3:07 
QuestionError after running GetUnauthorizedRequestToken.aspx Pin
Nilesh Ranjan13-Nov-15 1:29
Nilesh Ranjan13-Nov-15 1:29 
QuestionIs this still applicable or have they changed API? Pin
Member 1183930120-Aug-15 5:34
Member 1183930120-Aug-15 5:34 
Questionupload video on vimeo Pin
trupti shah9-Jun-15 20:25
trupti shah9-Jun-15 20:25 
QuestionWorks great!! Pin
MikeWeber1-Apr-15 13:01
MikeWeber1-Apr-15 13:01 
QuestionUpload Video on vimeo using ASP .NET C# Pin
Dharmendrakp25-Feb-15 23:21
professionalDharmendrakp25-Feb-15 23:21 
AnswerRe: Upload Video on vimeo using ASP .NET C# Pin
Dharmendrakp26-Feb-15 0:41
professionalDharmendrakp26-Feb-15 0:41 
sorry sir, I have not set web.config so find above problem. now I have solved its.
QuestionError... Pin
Selçuk İtmiş6-Aug-14 4:27
Selçuk İtmiş6-Aug-14 4:27 
QuestionNice article. Question? Pin
c#ivan26-Mar-14 5:39
c#ivan26-Mar-14 5:39 
GeneralMy vote of 1 Pin
bemar9-Sep-13 4:18
professionalbemar9-Sep-13 4:18 
QuestionAny more posts on Vimeo Pin
Member 906827629-Apr-13 9:53
Member 906827629-Apr-13 9:53 
Questionvimeo upload Pin
Padmanaban Thirunamam23-Dec-12 20:12
Padmanaban Thirunamam23-Dec-12 20:12 
BugThis sh*t doesn't work!! Pin
Sherlonus16-Sep-12 8:39
Sherlonus16-Sep-12 8:39 
GeneralMy vote of 1 Pin
Inge Eivind Henriksen1-Mar-12 2:34
Inge Eivind Henriksen1-Mar-12 2:34 
BugLength cannot be less than zero Pin
Inge Eivind Henriksen1-Mar-12 2:31
Inge Eivind Henriksen1-Mar-12 2:31 
QuestionIncorrect URI Pin
kydacroutman19-Feb-12 11:10
kydacroutman19-Feb-12 11:10 
AnswerRe: Incorrect URI Pin
Vinoth Arun Raj. X10-May-12 19:24
Vinoth Arun Raj. X10-May-12 19:24 
AnswerRe: Incorrect URI Pin
Anu10710-Jun-13 20:54
Anu10710-Jun-13 20:54 
AnswerRe: Incorrect URI Pin
Viral Trivedi12-Aug-14 19:14
Viral Trivedi12-Aug-14 19:14 
AnswerRe: Incorrect URI Pin
Member 1118937729-Oct-14 5:32
Member 1118937729-Oct-14 5:32 
GeneralRe: Incorrect URI Pin
vargroup1-May-16 23:47
vargroup1-May-16 23:47 
QuestionSpring.NET Social Pin
MaRuXeLo7930-Jan-12 12:11
MaRuXeLo7930-Jan-12 12:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.