2016-10-10 1 views
-4

bereitgestellt Ich möchte einen Stream erstellen und Live-Sendung es. Der Code funktioniert sehr gut auf dem lokalen Host, aber wenn es bereitgestellt wird, ist es ein Problem. Es erfordert nicht einmal eine Autorisierung für das Google-Konto. Sieht so aus, als ob es nicht einmal damit interagiert.YouTube Data API v3 funktioniert nicht, wenn auf Produktionsserver

Server Error in '/123456' Application.

Access to the path 'YouTubeDataAPISample.YouTube.Auth.Store' is denied.

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.UnauthorizedAccessException: Access to the path 'YouTubeDataAPISample.YouTube.Auth.Store' is denied.

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6 and IIS 7, and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating. If the application is impersonating via , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET access to a file, right-click the file in File Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[UnauthorizedAccessException: Access to the path 'YouTubeDataAPISample.YouTube.Auth.Store' is denied.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +217 System.IO.Directory.InternalCreateDirectory(String fullPath, String path, Object dirSecurityObj, Boolean checkHost) +11130032
System.IO.Directory.InternalCreateDirectoryHelper(String path, Boolean checkHost) +136 System.IO.Directory.CreateDirectory(String path) +33 Google.Apis.Util.Store.FileDataStore..ctor(String folder, Boolean fullPath) +72
Template.BusinessLogic.Implementation.YouTubeAPI.AuthenticateOauth(String clientId, String clientSecret, String userName, String apiKey) +220
Template.BusinessLogic.Implementation.YouTubeAPI..ctor() +63
Template.MVC5.Controllers.VideosController..ctor() +25

[TargetInvocationException: Exception has been thrown by the target of an invocation.] System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +113
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +232 System.Activator.CreateInstance(Type type, Boolean nonPublic) +83 System.Activator.CreateInstance(Type type) +66 System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +55

[InvalidOperationException: An error occurred when trying to create a controller of type 'Template.MVC5.Controllers.VideosController'. Make sure that the controller has a parameterless public constructor.]
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +178
System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +77
System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +88
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +191 System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +50
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +48
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +301 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

Autorisierungscode

private static YouTubeService AuthenticateOauth(string clientId, string clientSecret, string userName, string apiKey) 
     { 
      string[] scopes = new string[] { YouTubeService.Scope.Youtube, // view and manage your YouTube account 
              YouTubeService.Scope.YoutubeForceSsl, 
              YouTubeService.Scope.Youtubepartner, 
              YouTubeService.Scope.YoutubepartnerChannelAudit, 
              YouTubeService.Scope.YoutubeReadonly, 
              YouTubeService.Scope.YoutubeUpload}; 


      // here is where we Request the user to give us access, or use the Refresh Token that was previously stored in %AppData% 
      UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { ClientId = clientId, ClientSecret = clientSecret } 
                         , scopes 
                         , userName 
                         , CancellationToken.None 
                         , new FileDataStore("YouTubeDataAPISample.YouTube.Auth.Store")).Result; 

      YouTubeService service = new YouTubeService(new YouTubeService.Initializer() 
      { 
       ApiKey = apiKey, 
       HttpClientInitializer = credential, 
       ApplicationName = "YouTubeDataAPISample" 
      }); 

      return service;   
     } 

-Code für das Abrufen von Videos

 public PlaylistItemListResponse Videos() 
    { 
     var playlistItemsListRequest = service.PlaylistItems.List("snippet"); 

     var channelsListRequest = service.Channels.List("contentDetails"); 
     channelsListRequest.Mine = true; 
     foreach (var find in channelsListRequest.Execute().Items) 
     { 
      var uploadsListId = find.ContentDetails.RelatedPlaylists.Uploads; 

      var nextPageToken = ""; 
      while (nextPageToken != null) 
      { 

       playlistItemsListRequest.PlaylistId = uploadsListId; 
       playlistItemsListRequest.MaxResults = 50; 
       playlistItemsListRequest.PageToken = nextPageToken; 

       // Retrieve the list of videos uploaded to the authenticated user's channel. 
       var playlistItemsListResponse = playlistItemsListRequest.Execute(); 

       nextPageToken = playlistItemsListResponse.NextPageToken; 
      } 
     } 
     return playlistItemsListRequest.Execute(); 
    } 
+1

Haben Sie versucht, den Anweisungen auf der Fehlerseite zu folgen? Es sagt Ihnen genau, was Sie tun müssen, um das zugrunde liegende Problem zu sehen. – mason

+0

Können Sie uns Ihren Code zeigen? Es gibt nicht viel, was wir tun können, um ein Problem zu lösen, wenn wir nicht sehen können, was Sie zu tun versuchen. – MichaelDotKnox

+0

Aber denken Sie daran, dass es auf dem lokalen Host funktioniert, aber nicht bei der Bereitstellung. –

Antwort

0

den Fehler finden Sie eines von drei Dingen zu tun haben:

  1. Melden Sie sich an das Server und drücken Sie auf "localhost", um die Deta zu sehen gepackte Fehlerinformationen.
  2. Schreiben Sie einen benutzerdefinierten Code, um Protokolle an einen beliebigen Speicherort auszugeben, damit Sie sie lesen können.
  3. Deaktivieren Sie customErrors wie in der Fehlermeldung, die Sie haben. Dies ist eine schlechte Idee, aber es ist Ihr Anruf. Es sollte auf remoteonly eingestellt werden.
+1

Wir haben alle Ihre Lösungen ausprobiert. Für 1. Es funktioniert auf localhost, aber nicht auf einer implementierten Lösung. Zu 2. Es führt die Try- und Catch-Blöcke nicht aus. Für 3. Es besagt, dass das Objekt einer Referenz nicht auf ein Objekt eines Objekts festgelegt ist. –

+0

Fügen Sie also die Protokollierung außerhalb dieser try/catch-Blöcke hinzu. Es hört sich so an, als würde es dann Fehler werfen, oder? – KSib

+0

@ XolaniChristopher Sie schreiben 'InnerExeption', das ist sowieso keine Verwendung und Wahrscheinlichkeit' null'. Du willst 'ex.Message'. – BanksySan