我们的网站需要从后台代码(asp.net mvc 应用程序)将视频上传到 youtube。我正在尝试获取谷歌凭据,但是当我调用 AuthorizeAsync 时,应用程序只是挂起。我已经寻找了所有解决方案,但似乎没有一个能提供帮助。我已经在谷歌和堆栈溢出上搜索了明显的内容。我发现的大部分内容都提到应用程序可能无法访问 appdata 文件夹,因此我尝试将文件夹更改为位于 C 驱动器、D 驱动器和实际的 inetpub 位置。我测试并发现我能够让应用程序写入这些位置。
更具体地说,用户是我们的管理员,客户将视频上传给我们,管理员批准它们。当管理员批准后,它就会发布在我们的 YouTube 帐户上。管理员无需执行任何操作,只需单击“批准”按钮即可。
为了使这个问题成为一个实际问题,我该怎么做才能通过 AuthorizeAsync?如果您需要更多信息,请告诉我
UserCredential credential;
GoogleWebAuthorizationBroker.Folder = "YouTube.Auth.Store";
using (var stream = new FileStream(CredentialsPath, FileMode.Open,
FileAccess.Read))
{
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
// This OAuth 2.0 access scope allows an application to upload files to the
// authenticated user's YouTube channel, but doesn't allow other types of access.
new[] { YouTubeService.Scope.YoutubeUpload },
"user",
CancellationToken.None,
new FileDataStore("YouTube.Auth.Store")
).Result;
}
找到了一种方法来克服这个问题。
我改用 GoogleAuthorizationCodeFlow。结果是这样的:
ClientSecrets secrets = new ClientSecrets()
{
ClientId = CLIENT_ID,
ClientSecret = CLIENT_SECRET
};
var token = new TokenResponse { RefreshToken = REFRESH_TOKEN };
var credentials = new UserCredential(new GoogleAuthorizationCodeFlow(
new GoogleAuthorizationCodeFlow.Initializer
{
ClientSecrets = secrets
}),
"user",
token);
var service = new YouTubeService(new BaseClientService.Initializer()
{
HttpClientInitializer = credentials,
ApplicationName = "TestProject"
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)