我想创建一个Stream并直播它。代码在localhost上运行得非常好,但是在部署时它就是一个问题。它甚至不会在Google帐户上申请授权。看起来它甚至不与它互动。
' / 123456&#39>中的服务器错误应用
访问路径' YouTubeDataAPISample.YouTube.Auth.Store'是 拒绝。
描述:执行期间发生了未处理的异常 当前的网络请求。请查看堆栈跟踪了解更多信息 有关错误的信息以及它在代码中的起源。
异常详细信息:System.UnauthorizedAccessException:访问 路径' YouTubeDataAPISample.YouTube.Auth.Store'被拒绝。
ASP.NET无权访问所请求的资源。考虑 授予对ASP.NET请求的资源访问权限 身份。 ASP.NET具有基本进程标识(通常是 IIS 5上的{MACHINE} \ ASPNET或IIS 6和IIS 7上的网络服务,以及 IIS 7.5上配置的应用程序池标识,如果使用的话 该申请不是冒充。如果申请是 冒充通过,身份将是 匿名用户(通常是IUSR_MACHINENAME)或经过身份验证的用户 请求用户。
要授予对文件的ASP.NET访问权限,请右键单击“文件”中的文件 资源管理器,选择"属性"并选择“安全”选项卡。点击"添加" 添加适当的用户或组。突出显示ASP.NET帐户, 并选中所需访问的框。
来源错误:
执行期间生成了未处理的异常 当前的网络请求。有关的来源和位置的信息 可以使用下面的异常堆栈跟踪来识别异常。
堆栈追踪:
[UnauthorizedAccessException:访问路径 ' YouTubeDataAPISample.YouTube.Auth.Store'被拒绝。]
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(字符串 clientId,String clientSecret,String userName,String apiKey)+220
Template.BusinessLogic.Implementation.YouTubeAPI..ctor()+63
Template.MVC5.Controllers.VideosController..ctor()+25[TargetInvocationException:目标抛出了异常 调用。] System.RuntimeTypeHandle.CreateInstance(RuntimeType type,Boolean publicOnly,Boolean noCheck,Boolean& canBeCached, RuntimeMethodHandleInternal&安培; ctor,布尔& 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:尝试创建时出错 控制器类型' Template.MVC5.Controllers.VideosController'。使 确保控制器具有无参数的公共构造函数。]
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&控制器,IControllerFactory&厂) +191 System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext,AsyncCallback回调,对象状态)+50
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback回调,对象状态)+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
授权码
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;
}
检索视频的代码
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();
}
答案 0 :(得分:0)
要找到错误,您必须执行以下三项操作之一:
customErrors
。 这是一个坏主意,但它是您的电话。
应设置为remoteonly
。