小编Ben*_*nny的帖子

访问"Google.Apis.Auth"路径被拒绝

我正在用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 …
Run Code Online (Sandbox Code Playgroud)

.net iis oauth-2.0 iis-express asp.net-web-api

6
推荐指数
1
解决办法
2293
查看次数

标签 统计

.net ×1

asp.net-web-api ×1

iis ×1

iis-express ×1

oauth-2.0 ×1