我想使用API将视频上传到youtube。此外,我使用OAuth2身份验证来验证用户,但我无法弄清楚我哪里出错了。
我想在这里提一下,我现在正在我的localhost上测试它,所以我的重定向网址是localhost,我没有consumer_key和consumer_secret,但我使用的是HMAC-SHA1签名方法(对于未注册的域名)但是我在这里没有参数选项来提供签名方法
任何人都可以帮助我从中获取正确的东西吗?以下是我写的代码:
Dim CONSUMER_KEY As String = "anonymous"
Dim CONSUMER_SECRET As String = "anonymous"
Dim SCOPE As String = "https://gdata.youtube.com"
Dim parameters As OAuth2Parameters = New OAuth2Parameters
With parameters
.ClientId = ConfigurationManager.AppSettings.GetValues("ClientID").ToString
.ClientSecret = ConfigurationManager.AppSettings.GetValues("ClientSecret").ToString
.Scope = SCOPE
.RedirectUri = "http://localhost:13332/Default.aspx"
End With
Dim authorizationUrl As String = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters)
Dim AccessCode As String = authorizationUrl
parameters.AccessCode = AccessCode
OAuthUtil.GetAccessToken(parameters) ' **HERE I GOT ERROR ERROR AS The remote server returned an error: (400) Bad Request.**
Dim developerKey As String
developerKey = ConfigurationManager.AppSettings.GetValues("developerKey").ToString
Dim settings As YouTubeRequestSettings = New YouTubeRequestSettings("MyApp", developerKey, "AuthSubToken(I don't have it)")
Dim request As YouTubeRequest = New YouTubeRequest(settings)
'UPLOAD YOUTUBE VIDEO METADATA
Dim NewVideo As New Video
NeWvideo.Title = "My Test Movie"
NeWvideo.Tags.Add(New MediaCategory("Autos", YouTubeNameTable.CategorySchema))
NeWvideo.Keywords = "cars, funny"
NeWvideo.Description = "My description"
NeWvideo.YouTubeEntry.Private = False
NeWvideo.Tags.Add(New MediaCategory("mydevtag, anotherdevtag", YouTubeNameTable.DeveloperTagSchema))
'NeWvideo.YouTubeEntry.Location = New GeoRssWhere(37, -122)
Dim FormUploadToken As FormUploadToken = request.CreateFormUploadToken(NeWvideo)
Dim UploadUrl As String = FormUploadToken.Url
Dim UploadToken As String = FormUploadToken.Token
Session("posturl") = UploadUrl
Session("posttoken") = UploadToken
此外,我无法将用户重定向到Google登录页面以验证自己并向我的网络应用程序授予访问权限。
我再次要求将视频上传到youtube,使用基于浏览器的上传到特定用户帐户,而不是单个帐户,以及使用OAuth2认证流程。
请帮我弄清楚错误并在此提供解决方案? 提前谢谢。