gpt4 book ai didi

c# - GoogleWebAuthorizationBroker.AuthorizeAsync 挂起

转载 作者:可可西里 更新时间:2023-11-01 08:18:20 30 4
gpt4 key购买 nike

我们的网站需要从后台代码(asp.net mvc 应用程序)上传视频到youtube。我正在尝试获取 google 凭据,但是当我调用 AuthorizeAsync 时,应用程序只是挂起。我到处寻找解决方案,但似乎没有人帮忙。我已经在 google 和 stack overflow 上搜索了明显的内容。我发现的大部分内容都提到应用程序可能无法访问 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"
});

关于c# - GoogleWebAuthorizationBroker.AuthorizeAsync 挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27573272/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com