Search code examples
c#oauthvimeovimeo-api

Generate HTTP request with OAuth access token for Vimeo API in c#


I need to generate an http request to the vimeo api as per step 2 in this page, which is given below.

PUT https://i.cloud.vimeo.com/video/518016424
.... binary data of your file in the body ....

I alredy have an access token for this. Suppose the access token is "qw21we34". How do I generate an http request, with the token in the header and binary data in the body. I tried using WebClient() class as suggested here, but I cannot find a method to pass the OAuth access token with this type of request. Please note that there are no official libraries for Vimeo api that have this facility. Can anyone help?


Solution

  • For this you can use the WebClient() class. For the authentication, we need the access token from the previous request as well. I got it from my VimeoClient object called vc. That is up to you to figure out.

    WebClient wb = new WebClient();
    wb.Headers.Add("Authorization","Bearer" +vc.AccessToken);
    var file = wb.DownloadData(new Uri(myimageurl));
    var asByteArrayContent = wb.UploadData(new Uri(thumbnail_uri), "PUT", file);
    var asStringContent = Encoding.UTF8.GetString(asByteArrayContent);
    

    After sending this request, you should get a json response stating the success for asStringContent.