Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / ASP.NET

Vimeo API in ASP.NET using C#

3.00/5 (6 votes)
30 Jan 2012CPOL2 min read 74.7K   3.1K  
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)