如何解决如何使用带有Asp.Net MVC5的HTTPClient简单地向Vimeo调用授权请求?
我正在尝试使用HTTPClient(通过Asp.Net MVC5)向Vimeo OpenAPI调用授权请求。
请参阅以下文档网址中的使用授权代码授予部分。
https://developer.vimeo.com/api/authentication
当我要求授权并提供凭据时,我总是会从Vimeo服务器获得完整的html文件。
我的预期结果是通过JSON响应,如下所示,而不是完整的HTML文件。
{
"access_token": "{token}","token_type": "bearer","scope": "{scope_list}","user": "{user_representation}"
}
请参阅我尝试过的代码 第一次尝试:
private async Task<string> AuthorizationClientAsync()
{
string result = "";
using (HttpClient client = new HttpClient())
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
client.BaseAddress = new Uri("https://api.vimeo.com");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(ResponseTypes.Wildcard));
var byteArray = Encoding.ASCII.GetBytes(accesstoken);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer",accesstoken);
FormUrlEncodedContent form = new FormUrlEncodedContent(new List<keyvaluePair<string,string>>()
{
//new keyvaluePair<string,string>("type","POST")
new keyvaluePair<string,string>("response_type",clientId + ":" + clientSecret),new keyvaluePair<string,string>("client_id",clientId),string>("redirect_uri","127.0.0.1:44388"),string>("state","3232323"),string>("scope","private")
});
var response = await client.PostAsync("/oauth/authorize",form);
response.EnsureSuccessstatusCode();
result = await response.Content.ReadAsstringAsync();
}
return result;
}
第二次尝试如下
private async Task<string> AuthorizationClientAsync()
{
string result = "";
using (HttpClient client = new HttpClient())
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
client.BaseAddress = new Uri("https://api.vimeo.com");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(ResponseTypes.Wildcard));
var byteArray = Encoding.ASCII.GetBytes(accesstoken);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer",accesstoken);
string urlParts = "?response_type=" + clientId + ":" + clientSecret +
"&client_id=" + clientId + "&redirect_uri=127.0.0.1:44388" + "&state=121ssd&scope=private";
var response = await client.GetAsync("/oauth/authorize/" + urlParts);
response.EnsureSuccessstatusCode();
result = await response.Content.ReadAsstringAsync();
}
return result;
}
可能是因为使用了127.0.0.1:44388 redirect_uri ,但不确定。
请在下面输入完整错误:
<!DOCTYPE html>
<html lang="en">
<head>
<Meta charset="utf-8">
<Meta property="fb:app_id" content="19884028963">
<Meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="preconnect" href="//player.vimeo.com">
<link rel="preconnect" href="//i.vimeocdn.com">
<link rel="preconnect" href="//f.vimeocdn.com">
<link rel="search" type="application/opensearchdescription+xml" href="/search/opensearch.xml" title="Vimeo">
<link rel="logo" type="image/svg" href="https://f.vimeocdn.com/logo.svg">
<Meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=5.0,user-scalable=yes">
<Meta name="description" content="Join the web’s most supportive community of creators and get high-quality tools for hosting,sharing,and streaming videos in gorgeous HD with no ads.">
<link rel="canonical" href="/oauth/authorize">
<link rel="apple-touch-icon-precomposed" href="https://i.vimeocdn.com/favicon/main-touch_180">
<script>
(function() {
window._gtm = [{"language":"en","user_status":"logged_out","user_type":"none","ga_universal_id":"UA-76641-8","comscore_site_id":10348289}];
var gdprCookie = (document.cookie.match(/^(?:.*;)?\s*vimeo_gdpr_optin\s*=\s*([^;]+)(?:.*)?$/)||[,null])[1];
if (gdprCookie === '-1') {
return;
}
window._gtm.push({
'vuid': document.cookie.replace(/(?:(?:^|.*;\s*)vuid\s*\=\s*([^;]*).*$)|^.*$/,"$1"),'gtm.start': new Date().getTime(),'event': 'gtm.js'
});
var gtms = document.createElement('script'),node;
gtms.async = true;
gtms.type = 'text/javascript';
gtms.src = '//www.googletagmanager.com/gtm.js?id=GTM-RBKK&l=_gtm';
node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gtms,node);
})();
</script>
<script>
var googletag = googletag || {},gptadslots = [],language,has_uploaded,cohort;
googletag.cmd = googletag.cmd || [];
(function() {
var gdprCookie = (document.cookie.match(/^(?:.*;)?\s*vimeo_gdpr_optin\s*=\s*([^;]+)(?:.*)?$/)||[,null])[1];
if (gdprCookie === '-1') {
return;
}
var gads = document.createElement('script'),useSSL = 'https:' == document.location.protocol,node;
gads.async = true;
gads.type = 'text/javascript';
gads.src = (useSSL ? 'https:' : 'http:') + '//www.googletagservices.com/tag/js/gpt.js';
node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads,node);
})();
<script src="https://f.vimeocdn.com/js_opt/ablincoln_combined.min.js?6c4acb57"></script>
</head>
<body class="legacy" >
<div id="wrap">
<div id="create-facebook-header"></div>
<div id="topnav_outer_wrap">
<div id="ribbon" class="VimeoBrand_ColorRibbon "></div>
<style>
@-webkit-keyframes record_animation {
0%,20%,50%,80%,100% {
-webkit-transform: translateY(0);
transform: translateY(0);
}
40% {
-webkit-transform: translateY(2px);
transform: translateY(2px);
}
60% {
-webkit-transform: translateY(3px);
transform: translateY(3px);
}
}
@keyframes record_animation {
0%,100% {
-webkit-transform: translateY(0);
transform: translateY(0);
}
40% {
-webkit-transform: translateY(2px);
transform: translateY(2px);
}
60% {
-webkit-transform: translateY(3px);
transform: translateY(3px);
}
}
.logged_out_record_animation {
animation: record_animation 1.5s .25s 5;
}
.logged_in_record_animation {
animation: record_animation 1.5s .25s infinite;
}
.recorder_new_label {
text-transform: uppercase;
background-color: #1140C6;
color: #fff;
border-radius: 2px;
height: 20px;
line-height: 20px;
margin-left: 14px;
font-size: 10px;
width: 40px;
font-weight: 700;
text-align: center;
}
</style>
<script>
window.vimeo = window.vimeo || {};
</script>
<div id="topnav_desktop" class="topnav_desktop " role="banner">
<div class="topnav_desktop_wrapper">
<nav class="topnav_desktop_menu" role="navigation" aria-label="Main menu">
<ul class="topnav_menu_desktop_main" role="menubar">
<li class="topnav_desktop_menu_items" data-menu-id="join">
<a class="topnav_menu_join js-topnav_menu_auth" onclick="event.preventDefault();vimeo.Modal.create({size:'xsmall',content:'/join?modal=new'}).then(completeUserLogin)" data-ga-event-click="top_nav|join" data-fatal-attraction="container:top_nav|component:join" data-gtm-click="top_nav_join_click" href="//vimeo.com/join" title="Become a Vimeo member" rel="toggle" role="button" aria-owns="topnav_join">
Join </a>
</li>
<li class="topnav_desktop_menu_items" data-menu-id="login">
<a class="js-topnav_menu_auth" onclick="event.preventDefault();vimeo.Modal.create({size:'xsmall',content:'/log_in?modal=new'}).then(completeUserLogin)" data-ga-event-click="top_nav|login" data-fatal-attraction="container:top_nav|component:login" data-gtm-click="top_nav_login_click" href="//vimeo.com/log_in" title="Log in to your account" rel="toggle" role="button" aria-owns="topnav_login">
Log in </a>
</li>
<li class="topnav_desktop_menu_items" data-menu-id="pricing">
<a data-fatal-attraction="container:top_nav|component:pricing" data-gtm-click="top_nav_pricing_click" href="//vimeo.com/upgrade" title="Pricing" rel="toggle" role="button" aria-owns="topnav_pricing">
Pricing </a>
</li>
<li class="topnav_desktop_menu_items" data-menu-id="product">
<a onclick="event.preventDefault();event.target.blur();" class="topnav_menu_no_link topnav_has_dropdown topnav_icon_chevron_a" href="#" title="Product" rel="toggle" role="button" aria-owns="topnav_product">
Product </a>
<div class="topnav_desktop_menu_items_dropdown--wrapper" role="menu" aria-hidden="true" id="topnav_product">
<div class="topnav_desktop_solutions--features">
<div class="topnav_desktop_menu_items_dropdown--labels">FEATURES</div>
<ul class="topnav_desktop_menu_items_list">
<li class="topnav_desktop_menu_items_dropdown_item" role="menuitem" tabindex="-1">
<a data-fatal-attraction="container:top_nav|component:product|keyword:video_player" data-gtm-click="top_nav_product_video_player" href="//vimeo.com/features/video-player" title="Video player">Video player</a>
</li>
<li class="topnav_desktop_menu_items_dropdown_item" role="menuitem" tabindex="-1">
<a data-fatal-attraction="container:top_nav|component:product|keyword:screen_recorder" data-gtm-click="top_nav_product_screen_recorder" href="//vimeo.com/features/screen-recorder" title="Screen recorder">Screen recorder</a>
</li>
<li class="topnav_desktop_menu_items_dropdown_item" role="menuitem" tabindex="-1">
<a data-fatal-attraction="container:top_nav|component:product|keyword:live_streaming" data-gtm-click="top_nav_product_live_streaming" href="//vimeo.com/live" title="Live streaming">Live streaming</a>
</li>
<li class="topnav_desktop_menu_items_dropdown_item" role="menuitem" tabindex="-1">
<a data-fatal-attraction="container:top_nav|component:product|keyword:privacy" data-gtm-click="top_nav_product_privacy" href="//vimeo.com/features/video-privacy" title="Privacy">Privacy</a>
</li>
<li class="topnav_desktop_menu_items_dropdown_item" role="menuitem" tabindex="-1">
<a data-fatal-attraction="container:top_nav|component:product|keyword:collaboration" data-gtm-click="top_nav_product_collaboration" href="//vimeo.com/features/video-collaboration" title="Collaboration">Collaboration</a>
</li>
<li class="topnav_desktop_menu_items_dropdown_item" role="menuitem" tabindex="-1">
<a data-fatal-attraction="container:top_nav|component:product|keyword:distribution" data-gtm-click="top_nav_product_distribution" href="//vimeo.com/features/video-marketing" title="distribution and marketing">distribution & marketing</a>
</li>
<li class="topnav_desktop_menu_items_dropdown_item" role="menuitem" tabindex="-1">
<a data-fatal-attraction="container:top_nav|component:product|keyword:monetization" data-gtm-click="top_nav_product_monetization" href="//vimeo.com/features/video-monetization" title="Monetization">Monetization</a>
</li>
<li class="topnav_desktop_menu_items_dropdown_item" role="menuitem" tabindex="-1">
<a data-fatal-attraction="container:top_nav|component:product|keyword:analytics" data-gtm-click="top_nav_product_analytics" href="//vimeo.com/features/video-analytics" title="Analytics">Analytics</a>
</li>
<li class="topnav_desktop_menu_items_dropdown_item" role="menuitem" tabindex="-1">
<a data-fatal-attraction="container:top_nav|component:product|keyword:hosting" data-gtm-click="top_nav_product_hosting" href="//vimeo.com/features/online-video-hosting" title="Hosting and management">Hosting & management</a>
</li>
<a href="/upgrade" class="topnav_desktop_menu_items_dropdown--compare_plans" data-fatal-attraction="container:top_nav|component:product|keyword:compare_plans|target:/upgrade|type:click">Compare Plans</a>
</ul>
</div>
<div class="topnav_desktop_solutions--services">
<div class="topnav_desktop_menu_items_dropdown--labels">SERVICES</div>
<div class="topnav_desktop_solutions--services_container">
<div class="services_wrapper">
<a data-fatal-attraction="container:top_nav|component:solutions|keyword:create|target:/create|type:click" class="topnav_desktop_solutions--services_block" href="//vimeo.com/create">
<h3>
Create </h3>
<p>Make social videos in an instant: use custom templates to tell the right story for your business.</p>
</a>
</div>
<div class="services_wrapper">
<a data-fatal-attraction="container:top_nav|component:solutions|keyword:for_hire|target:/for-hire|type:click" class="topnav_desktop_solutions--services_block" href="//vimeo.com/for-hire">
<h3>
For Hire </h3>
<p>Post jobs,find pros,and collaborate commission-free in our professional marketplace.</p>
</a>
</div>
<div class="services_wrapper">
<a data-fatal-attraction="container:top_nav|component:solutions|keyword:enterprise|target:/enterprise|type:click" class="topnav_desktop_solutions--services_block" href="//vimeo.com/enterprise">
<h3>
Enterprise </h3>
<p>Get your team aligned with all the tools you need on one secure,reliable video platform.</p>
</a>
</div>
<div id="main">
<div id="content">
<h3 class="hot">Uh oh,something went wrong!</h3>
<p>An error has occurred. You won't be able to connect to Vimeo until it is fixed by the developer.</p>
<p>Looks like you hit a snag when trying to connect <strong>DemoApp</strong> with your account.</p>
<p>Please contact the app owner and let him or her kNow that <strong>DemoApp</strong> was unable to create an oauth2 authorization code because the redirect URI is missing.</p>
<p><a class="btn btn_gray" onclick="window.history.back();return false">Go back</a></p>
</div>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。