Click here to Skip to main content
Click here to Skip to main content

Tagged as

Vimeo API in ASP.NET using C#

, 30 Jan 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
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

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

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)

Share

About the Author

Fazlur Rahman
Software Developer (Senior) MediaNet Group
United Arab Emirates United Arab Emirates
I am Bachelor in CSE from KUET,Bangladesh. I have more than 6 years experience in ASP.NET and C# and currently working in a software company in Dubai,UAE as a Senior 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

 
QuestionError... PinmemberSelçuk İtmiş6-Aug-14 4:27 
QuestionNice article. Question? Pinmemberc#ivan26-Mar-14 5:39 
GeneralMy vote of 1 Pinmemberbemar9-Sep-13 4:18 
QuestionAny more posts on Vimeo PinmemberMember 906827629-Apr-13 9:53 
Hi Fazlur,
 
This article is helpful. I wasn't able to find but do you have any more articles posted by integrating Vimeo with the website using asp.net? or if you can point me in some direction that would be great as well.
Questionvimeo upload PinmemberPadmanaban Thirunamam23-Dec-12 20:12 
BugThis sh*t doesn't work!! PinmemberSherlonus16-Sep-12 8:39 
GeneralMy vote of 1 PinmemberInge Eivind Henriksen1-Mar-12 2:34 
BugLength cannot be less than zero PinmemberInge Eivind Henriksen1-Mar-12 2:31 
QuestionIncorrect URI Pinmemberkydacroutman19-Feb-12 11:10 
AnswerRe: Incorrect URI Pingroupvinoth.arunraj8610-May-12 19:24 
AnswerRe: Incorrect URI PinmemberAnu10710-Jun-13 20:54 
AnswerRe: Incorrect URI PinmemberViral Trivedi12-Aug-14 19:14 
QuestionSpring.NET Social PinmemberMaRuXeLo7930-Jan-12 12:11 

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

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

| Advertise | Privacy | Mobile
Web01 | 2.8.141015.1 | Last Updated 30 Jan 2012
Article Copyright 2012 by Fazlur Rahman
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid