简体   繁体   中英

Authorising POST to Vimeo API with C# HttpClient

I am trying to make a POST to the Vimeo API but I am getting 401 Authorization Required .

This is my code for the request (I am just sending the first request that the docs says should return me a ticket ID for uploading).

HttpClient client = new HttpClient();

client.BaseAddress = new Uri("https://api.vimeo.com");
var byteArray = Encoding.ASCII.GetBytes(accessToken);
client.DefaultRequestHeaders.Authorization =
            new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));

var form = new FormUrlEncodedContent(new List<KeyValuePair<string, string>>()
            {
                new KeyValuePair<string, string>("type","POST")
            });
var response = await client.PostAsync("/me/videos", form);
response.EnsureSuccessStatusCode();

var result = await response.Content.ReadAsStringAsync();

I also tried adding access token like this:

client.DefaultRequestHeaders.Authorization =
            new AuthenticationHeaderValue("Basic", accessToken);

It always return 401.

What is proper way to add the access token?

This is how header must be:

client.DefaultRequestHeaders.Authorization =
            new AuthenticationHeaderValue("Bearer", accessToken);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM