【发布时间】:2019-11-06 12:03:04
【问题描述】:
我面临以下问题:我创建了一个 google 服务帐户,现在我正在尝试使用 c# 对 Google API 和 YouTube Data API 进行授权 API 调用。这是我的示例代码:
string filePath = @"~\my-path\Default-GASvcAcct-508d097b0bff.json"
using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
googleCredential = GoogleCredential.FromStream(stream);
}
if (googleCredential.IsCreateScopedRequired)
{
googleCredential.CreateScoped(
new string[]
{
YouTubeService.Scope.YoutubeReadonly,
YouTubeService.Scope.YoutubeUpload,
YouTubeService.Scope.Youtube,
YouTubeService.Scope.YoutubeForceSsl,
YouTubeService.Scope.Youtubepartner,
YouTubeService.Scope.YoutubepartnerChannelAudit
});
}
YouTubeService service = new YouTubeService(new BaseClientService.Initializer()
{
HttpClientInitializer = googleCredential,
});
service.Videos.List()
代码构建成功,但是当我启动程序时,我收到以下错误消息:
System.IO.FileNotFoundException: '无法加载文件或程序集 'BouncyCastle.Crypto,版本=1.7.4137.9688,文化=中性, PublicKeyToken=a4292a325f69b123' 或其依赖项之一。这 系统找不到指定的文件。'
有人知道如何修复此错误,是否可以使用服务帐户凭据向 YouTube 数据 API 发出请求?
提前致谢!
【问题讨论】:
-
您使用什么版本的 .NET?
-
您使用的是哪个版本的 NuGet 包?请注意,您也忽略了
CreateScoped的返回值 - 您应该拥有googleCredential = googleCredential.CreateScoped(...) -
检查这个可能对你有帮助stackoverflow.com/questions/21132531/…
-
@Baruch 在这个项目中我使用的是 .NET 4.5 - 你认为 .NET 的版本可能是导致此错误的原因吗?在 using 语句中已抛出异常。
-
@MangeshAuti 问题不在于实现列表视频功能,而是实现授权。
标签: c# youtube-data-api google-oauth google-api-dotnet-client service-accounts