6

I'm creating a .net web api (.net 4.5) with Visual Studio 2013 that calls the Google.Apis.YouTube.v3 to search videos. Everything works as fine when I'm using IIS Express (e.g. http:// localhost:12345/), but once I changed to use Local IIS (e.g. http:// localhost/HelloWorldWebApi) it throws me a System.UnauthorizedAccessException {"Access to the path 'Google.Apis.Auth' is denied."}.

I have searched hours online and found nothing.

My dev environment: Windows 8.1, Visual Studio 2013, IIS 8.5

Codes:

    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);
    }

Thanks in advance for all the helps!

Benny
  • 61
  • 3
  • ## Check Below Link:## http://stackoverflow.com/questions/23405767/system-unauthorizedaccessexception-access-to-the-path-google-apis-auth-is-deni – Nima Rostami Jun 16 '15 at 11:35

1 Answers1

0

Could it be that the reason of this problem is the IIS Express runs under a different account (the one that you are logged in) then the IIS instant (depending from the pool configuration but default it is ApplicationPoolIdentity) ? I think the IIS account does not have the right to the resource that contains Google.Apis.Auth.