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!