如何获取视频上传 link 以将视频上传到我的 Vimeo 帐户?
How do I get the video upload link for uploading a video to my Vimeo account?
如何使用带有 C# 和 .Net Core 的 Vimeo API 获取视频上传 link 以将视频上传到我的 Vimeo 帐户?
答案将是一个将像这样调用的方法:
var vimeoUploadUrl = await getVimeoUploadUrl(videoFileSizeInBytes, accessToken).ConfigureAwait(false);
要做到这一点,你必须有一个 Vimeo 帐户(这适用于 Plus 级别或更高级别,不知道其他的),已经创建了一个 Vimeo 应用程序(在 Vimeo 中),授予它上传权限,并且获得了访问令牌。一切就绪后,代码如下:
HttpClient httpClient = new HttpClient();
public async Task<string> getVimeoUploadUrl(int videoFileSize, string accessToken)
{
var vimeoUploadUrl = "";
string vimeoApiUrl = "https://api.vimeo.com/me/videos"; // Vimeo URL
try
{
string body =
@"{'upload': {'approach': 'post','size': '" + videoFileSize + "'}}".Replace("'", "\"");
HttpContent content = new StringContent(body);
using (var requestMessage = new HttpRequestMessage(HttpMethod.Post, vimeoApiUrl))
{
requestMessage.Headers.Authorization =
new AuthenticationHeaderValue("Bearer", accessToken);
requestMessage.Headers.Add("Accept", "application/vnd.vimeo.*+json;version=3.4");
requestMessage.Headers.Add("ContentType", "application/json");
requestMessage.Content = content;
var response = await httpClient.SendAsync(requestMessage).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
var result = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var myJsonObject = JObject.Parse(result);
vimeoUploadUrl = myJsonObject.SelectToken("upload.upload_link").ToString();
}
}
catch (Exception err)
{
// Do your own error handling!
}
return vimeoUploadUrl;
}
如何使用带有 C# 和 .Net Core 的 Vimeo API 获取视频上传 link 以将视频上传到我的 Vimeo 帐户?
答案将是一个将像这样调用的方法:
var vimeoUploadUrl = await getVimeoUploadUrl(videoFileSizeInBytes, accessToken).ConfigureAwait(false);
要做到这一点,你必须有一个 Vimeo 帐户(这适用于 Plus 级别或更高级别,不知道其他的),已经创建了一个 Vimeo 应用程序(在 Vimeo 中),授予它上传权限,并且获得了访问令牌。一切就绪后,代码如下:
HttpClient httpClient = new HttpClient();
public async Task<string> getVimeoUploadUrl(int videoFileSize, string accessToken)
{
var vimeoUploadUrl = "";
string vimeoApiUrl = "https://api.vimeo.com/me/videos"; // Vimeo URL
try
{
string body =
@"{'upload': {'approach': 'post','size': '" + videoFileSize + "'}}".Replace("'", "\"");
HttpContent content = new StringContent(body);
using (var requestMessage = new HttpRequestMessage(HttpMethod.Post, vimeoApiUrl))
{
requestMessage.Headers.Authorization =
new AuthenticationHeaderValue("Bearer", accessToken);
requestMessage.Headers.Add("Accept", "application/vnd.vimeo.*+json;version=3.4");
requestMessage.Headers.Add("ContentType", "application/json");
requestMessage.Content = content;
var response = await httpClient.SendAsync(requestMessage).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
var result = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var myJsonObject = JObject.Parse(result);
vimeoUploadUrl = myJsonObject.SelectToken("upload.upload_link").ToString();
}
}
catch (Exception err)
{
// Do your own error handling!
}
return vimeoUploadUrl;
}