0

I am trying to connect to Google Youtube API.

The last thing I changed is : adding the line new FileDataStore(folder). The code works well on localhost but triggers the following error on the server:

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ComponentModel.Win32Exception: Access is denied

Here is my code:

public async Task<List<string>> GetSubscriptionsRequest(string id)
    {
        ClientSecrets secrets = new ClientSecrets() // tutorial : https://developers.google.com/identity/sign-in/web/devconsole-project
        {
            ClientId = "780499768563-j5dcgafhl5rg6ivh452iihcqe57gjvut.apps.googleusercontent.com",
            ClientSecret = "--"
        };

        string userid = id ?? "user";
        System.Diagnostics.Debug.WriteLine("userid " + userid);

        var folder = System.Web.HttpContext.Current.Server.MapPath("/App_Data/MyGoogleStorage");


        var credentialMethod2 = await GoogleWebAuthorizationBroker.AuthorizeAsync(
            secrets,
            // This OAuth 2.0 access scope allows an application to upload files to the
            // authenticated user's YouTube channel, but doesn't allow other types of access.
            new[]
            {
                YouTubeService.Scope.YoutubeUpload, YouTubeService.Scope.Youtube, YouTubeService.Scope.YoutubeForceSsl
            ,YouTubeService.Scope.YoutubeReadonly
            },
            userid, // if I can change this from "user" I get triggered to http://localhost:57464/authorize/?code=4/QUj58_0CI1abkj3fJptZQpw-AxCWUw5eYOLwg9edaqk# to accept Youtube permission for the Google user
            CancellationToken.None,
            new FileDataStore(folder)
            //new FileDataStore(this.GetType().ToString()) // CRITICAL
        );

        var youtubeService = new YouTubeService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credentialMethod2,
            ApplicationName = Assembly.GetExecutingAssembly().GetName().Name // will give the name of this .net project
        });


        var subscriptionsListRequest = youtubeService.Subscriptions.List("snippet");
        subscriptionsListRequest.MaxResults = 50;
        subscriptionsListRequest.Mine = true;
        var subscriptionsListResponse = await subscriptionsListRequest.ExecuteAsync();
        List<string> lstSubscriptionId = new List<string>();
        foreach (var channel in subscriptionsListResponse.Items)
        {
            //System.Diagnostics.Debug.WriteLine(channel.Snippet.Title); // The Young Turks
            //System.Diagnostics.Debug.WriteLine(channel.Snippet.ResourceId.ChannelId);
            lstSubscriptionId.Add(channel.Snippet.ResourceId.ChannelId);
        }

        return lstSubscriptionId;

    }

Here is the stack trace: Stack Trace:

[Win32Exception (0x80004005): Access is denied]
System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) +756
System.Diagnostics.Process.Start() +131
System.Diagnostics.Process.Start(ProcessStartInfo startInfo) +49 
Google.Apis.Auth.OAuth2.<ReceiveCodeAsync>d__6.MoveNext() +280
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +92

    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
    Google.Apis.Auth.OAuth2.<AuthorizeAsync>d__8.MoveNext() +540
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +92
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
    Google.Apis.Auth.OAuth2.<AuthorizeAsync>d__4.MoveNext() +395
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +92
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
    Google.Apis.Auth.OAuth2.<AuthorizeAsync>d__1.MoveNext() +268
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +92
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
    Scraper_v1.Infrastructure.<GetSubscriptionsRequest>d__15.MoveNext() +576
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +92
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
    Scraper_v1.Controllers.<Mysubscriptions>d__19.MoveNext() +312
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +92
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
    lambda_method(Closure , Task ) +33
    System.Threading.Tasks.TaskHelpersExtensions.ThrowIfFaulted(Task task) +35
    System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +67
    System.Web.Mvc.Async.<>c__DisplayClass3f.<BeginInvokeAsynchronousActionMethod>b__3e(IAsyncResult asyncResult) +16
    System.Web.Mvc.Async.WrappedAsyncResult`1.End() +58
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +49
   System.Web.Mvc.Async.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() +57
   System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +223
   System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult) +15
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +58
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +49
   System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +24
   System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +102
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +58
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +44
   System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +15
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +16
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +58
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +54
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +16
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +58
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +44
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +12
   System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +25
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +16
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +58
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +44
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +11
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9744373
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

Thanks

Nicoara Talpes
  • 710
  • 1
  • 13
  • 28
  • [`Win32Exception Class`](https://msdn.microsoft.com/en-us/library/system.componentmodel.win32exception(v=vs.110).aspx) will throw an exception for a Win32 error code. As suggested [here](http://blog.brendanlacanette.com/2015/07/systemcomponentmodelwin32exception.html), change the .NET application's framework version to 4.5. Also erase the `` section from the `web.config` if it's throwing an error when you build. Here's a related [thread](http://stackoverflow.com/questions/30017679/youtube-api-with-asp-net-4-5-webforms-oauth2-issue) which might help. – abielita Mar 16 '17 at 07:51
  • The framework is already 4.5. I don't have any compiler tag. Thanks – Nicoara Talpes Mar 16 '17 at 13:04

0 Answers0