我想使用 API 将视频上传到 youtube。此外,我正在使用 OAuth2 身份验证来验证用户身份,但我无法弄清楚我哪里出错了。
我想在这里提一下,现在我正在我的本地主机上测试它,所以我的重定向 url 是本地主机,我没有 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
此外,我无法获得将用户重定向到谷歌登录页面以验证自己并授予对我的 Web 应用程序的访问权限的过程。
在这里,我的要求是使用基于浏览器的上传到特定用户帐户而不是单个帐户以及使用 OAuth2 身份验证过程将视频上传到 youtube。
请帮我找出错误并在这里为我提供解决方案?提前致谢。