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

Vimeo API in ASP.NET using C#

By , 30 Jan 2012
 

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)

About the Author

Fazlur Rahman
Software Developer (Senior) MediaNet Group
United Arab Emirates United Arab Emirates
Member
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.


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionAny more posts on VimeomemberMember 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 uploadmemberPadmanaban Thirunamam23 Dec '12 - 20:12 
hi,
thanks for your article.
 
Regards
Padmanaban.
BugThis sh*t doesn't work!!memberSherlonus16 Sep '12 - 8:39 
This sh*t doesn't work!!
Error: Length cannot be less than zero. Parameter name: length
rhheyter

GeneralMy vote of 1memberInge Eivind Henriksen1 Mar '12 - 2:34 
Dont work.
BugLength cannot be less than zeromemberInge Eivind Henriksen1 Mar '12 - 2:31 
Crashes on GetUnauthorizedRequestToken.aspx with the error
 
Length cannot be less than zero.
Parameter name: length
 
[ArgumentOutOfRangeException: Length cannot be less than zero.
Parameter name: length]
System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) +7494519
System.String.Substring(Int32 startIndex, Int32 length) +11
VimeoNET.UrlBuilder.GenerateTimeStamp() in F:\Development\ResearchAndDevelopment\YouTube API\Source Code\YouTube\Vimeo.API\UrlBuilder.cs:206
VimeoNET.UrlBuilder.BuildUrl(String url, String authToken, String authSecret, String authVerifier, String methodName, VideoUploadMethod videoPostMethod, String fileName, String ticketId, Boolean authCallback, String videoId, String title, String description, String tags) in F:\Development\ResearchAndDevelopment\YouTube API\Source Code\YouTube\Vimeo.API\UrlBuilder.cs:16
VimeoNET.UrlBuilder.BuildRequestTokenUrl() in F:\Development\ResearchAndDevelopment\YouTube API\Source Code\YouTube\Vimeo.API\UrlBuilder.cs:88
VimeoNET.VimeoAPI.GetUnauthorizedRequestToken() in F:\Development\ResearchAndDevelopment\YouTube API\Source Code\YouTube\Vimeo.API\VimeoAPI.cs:14
GetUnauthorizedRequestToken.Page_Load(Object sender, EventArgs e) in d:\dev\VimeoAPI.WebSite\GetUnauthorizedRequestToken.aspx.cs:10
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
Inge Henriksen
Contact: inge DOT henriksen AT bouvet DOT no

QuestionIncorrect URImemberkydacroutman19 Feb '12 - 11:10 
I attempted to run this project, however I ran into an issue:
 
Value cannot be null.
Parameter name: requestUriString
 
at System.Net.WebRequest.Create(String requestUriString)   at VimeoNET.VimeoAPI.PostVideo(String endPoint, String fileName, Byte[] fileContent) in F:\Development\ResearchAndDevelopment\YouTube API\Source Code\YouTube\Vimeo.API\VimeoAPI.cs:line 442
   at VimeoNET.VimeoAPI.UploadVideo(String filePath, String title, String description, String tags, Boolean checkQuota) in F:\Development\ResearchAndDevelopment\YouTube API\Source Code\YouTube\Vimeo.API\VimeoAPI.cs:line 191
   at UploadVideo.btnUpload_Click(Object sender, EventArgs e) in d:\VimeoAPI.WebSite\UploadVideo.aspx.cs:line 22
AnswerRe: Incorrect URIgroupvinoth.arunraj8610 May '12 - 19:24 
Hi Me too have this same error can u help us in this part.
QuestionSpring.NET SocialmemberMaRuXeLo7930 Jan '12 - 12:11 
You should take a look to Spring.NET Social to write your own Client:
http://www.springframework.net/social/[^]

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 30 Jan 2012
Article Copyright 2012 by Fazlur Rahman
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid