gpt4 book ai didi

.net - 访问路径 'Google.Apis.Auth' 被拒绝

转载 作者:行者123 更新时间:2023-12-04 16:10:23 25 4
gpt4 key购买 nike

我正在使用 Visual Studio 2013 创建一个 .net web api (.net 4.5),它调用 Google.Apis.YouTube.v3 来搜索视频。当我使用 IIS Express(例如 http://localhost:12345/)时,一切正常,但是一旦我更改为使用本地 IIS(例如 http://localhost/HelloWorldWebApi),它就会向我抛出 System.UnauthorizedAccessException {"拒绝访问路径“Google.Apis.Auth”。"}。

我在网上搜索了几个小时,一无所获。

我的开发环境:
Windows 8.1、Visual Studio 2013、IIS 8.5

代码:

    public IEnumerable<MyVideo> Get(string search)
{
try
{
string resourceName = "HelloWorldWebApi.client_secret.json";
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
{
Credential(stream).Wait();
}

YouTubeService youtube = new YouTubeService(new BaseClientService.Initializer()
{
HttpClientInitializer = _credential,
ApplicationName = "HelloWorldWebApiTest"
});

SearchResource.ListRequest listRequest = youtube.Search.List("snippet");
listRequest.Q = search;
listRequest.MaxResults = 5;
listRequest.Type = "video";
SearchListResponse searchResponse = listRequest.Execute();

List<MyVideo> videos = new List<MyVideo>();
foreach (SearchResult result in searchResponse.Items)
{
videos.Add(new MyVideo(result.Snippet.Title));
}

return videos;
}
catch (Exception ex)
{
throw ex;
}
}

private async Task Credential(Stream stream)
{
_credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
new[] { YouTubeService.Scope.YoutubeReadonly },
"user", CancellationToken.None);
}

在此先感谢所有帮助!

最佳答案

可能是这个问题的原因是 IIS Express 在不同的帐户(您登录的帐户)下运行,然后是 IIS 即时(取决于池配置,但默认为 ApplicationPoolIdentity)?我认为 IIS 帐户无权访问包含 Google.Apis.Auth 的资源。

关于.net - 访问路径 'Google.Apis.Auth' 被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20306647/

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