Google api c#-无法使用YouTube身份验证令牌生成文件
我正在开发一个asp.net应用程序,用于在YouTube上上传视频,该应用程序使用IIS服务器。成功上载需要刷新令牌。以下代码显示了应生成具有身份验证访问权的新文件并在作为参数传递的文件路径中刷新令牌的方法:Google api c#-无法使用YouTube身份验证令牌生成文件,google-api,youtube-api,google-api-dotnet-client,youtube-data-api,Google Api,Youtube Api,Google Api Dotnet Client,Youtube Data Api,我正在开发一个asp.net应用程序,用于在YouTube上上传视频,该应用程序使用IIS服务器。成功上载需要刷新令牌。以下代码显示了应生成具有身份验证访问权的新文件并在作为参数传递的文件路径中刷新令牌的方法: private void SetRefreshToken(string refresh_token_path) { ClientSecrets secrets = new ClientSecrets()
private void SetRefreshToken(string refresh_token_path)
{
ClientSecrets secrets = new ClientSecrets()
{
ClientId = this.clientId,
ClientSecret = this.clientSecret
};
UserCredential credentials;
try
{
// Approach 1
credentials = GoogleWebAuthorizationBroker.AuthorizeAsync(
secrets,
new[]
{
YouTubeService.Scope.YoutubeReadonly,
YouTubeService.Scope.YoutubeUpload,
YouTubeService.Scope.Youtube,
YouTubeService.Scope.YoutubeForceSsl,
YouTubeService.Scope.Youtubepartner,
YouTubeService.Scope.YoutubepartnerChannelAudit
},
"user",
CancellationToken.None,
new FileDataStore(refresh_token_path)
).Result;
// Approach 2
//IAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow(
// new GoogleAuthorizationCodeFlow.Initializer
// {
// ClientSecrets = secrets,
// Scopes = new[] {
// YouTubeService.Scope.YoutubeReadonly,
// YouTubeService.Scope.YoutubeUpload,
// YouTubeService.Scope.Youtube,
// YouTubeService.Scope.YoutubeForceSsl,
// YouTubeService.Scope.Youtubepartner,
// YouTubeService.Scope.YoutubepartnerChannelAudit
// },
// DataStore = new FileDataStore(refresh_token_path, true)
// });
}
catch (Exception ex)
{
System.IO.File.WriteAllText(@"D:\error.txt", string.Format("{0}{1}{2}", ex.Message, Environment.NewLine, ex.StackTrace));
}
}
当我启动它时,如果通过“GoogleWebAuthorizationBroker.AuthorizationAsync”方法使用方法1,则执行流在该方法中冻结。如果我使用方法2-通过“GoogleAuthorizationCodeFlow.Initializer”,代码流将继续,不会引发任何异常,但事实上,在指定的文件路径“refresh\u token\u path”中没有创建的文件。
当我在测试控制台应用程序中启动此代码时,它在这两种情况下都可以正常工作
你能给我一个约会吗?原因是什么?我该怎么解决
提前谢谢 文件数据存储需要凭据文件所在的路径。我会检查并确保iis有权限访问您告诉它要将文件写入的路径。谢谢您的回答!我已经读过这篇文章,我甚至在那里提出了同样的问题,但不幸的是,那里的答案对我没有帮助。我授予IIS服务器访问指定文件路径的完全权限:new FileDataStore(refresh\u token\u path,true),因此问题出现在其他地方。我假设您使用的是库的1.20?你想试试旧版本吗?我正在使用v.1.19。你的问题解决了吗。文件数据存储需要凭据文件所在的路径。我会检查并确保iis有权限访问您告诉它要将文件写入的路径。谢谢您的回答!我已经读过这篇文章,我甚至在那里提出了同样的问题,但不幸的是,那里的答案对我没有帮助。我授予IIS服务器访问指定文件路径的完全权限:new FileDataStore(refresh\u token\u path,true),因此问题出现在其他地方。我假设您使用的是库的1.20?你想试试旧版本吗?我正在使用v.1.19。你的问题解决了吗。