c# - Using Youtube ApiV3 locally as well as on server -


i beginner in c# helpful if explain issue in simple words. have issue regarding uploading video on youtube channel through server using youtube api v3 when run code locally have no issues uploading video.but hosting on iis/server gives object reference error. below code trying execute video uploading written on upload button.

protected async void btnupload_click(object sender, eventargs e) {     if (txtvideotitle.text != "" && txtfileupload.hasfile)     {         date = datetime.now;         string client_id = configurationmanager.appsettings["clientid"];         string client_secret = configurationmanager.appsettings["clientsecret"];                         var youtubeservice = authenticateoauth(client_id, client_secret,"singleuser");         if (youtubeservice == null) throw new  argumentnullexception("youtubeservice");         var video = new video();         video.snippet = new videosnippet();         video.snippet.title = txtvideotitle.text;         video.snippet.description = txtvideodescription.text;         video.snippet.tags = new string[] { "tag1", "tag2" };                         video.status = new videostatus();         video.status.privacystatus = "unlisted";         if (video == null) throw new argumentnullexception("video");         var filename = txtfileupload.filename;         stream filepath = txtfileupload.postedfile.inputstream;         var videosinsertrequest = youtubeservice.videos.insert(video,"snippet,status", filepath, "video/*");         videosinsertrequest.responsereceived += videosinsertrequest_responsereceived;         await videosinsertrequest.uploadasync();         message.text = "video uploaded successfully!!!";     }     else     {         message.text = "please enter required details...";     } }  public static youtubeservice authenticateoauth(string client_id, string client_secret, string v)     {         string[] scopes = new string[] { youtubeservice.scope.youtube,                                          youtubeservice.scope.youtubeforcessl,                                          youtubeservice.scope.youtubepartner,                                          youtubeservice.scope.youtubepartnerchannelaudit,                                          youtubeservice.scope.youtubereadonly,                                          youtubeservice.scope.youtubeupload};          try         {             // here request user give access, or use refresh token stored in %appdata%             usercredential credential = googlewebauthorizationbroker.authorizeasync(new clientsecrets { clientid = client_id, clientsecret = client_secret }                                                                                          , scopes                                                                                          , v                                                                                          , cancellationtoken.none                                                                                          , new filedatastore("drive.auth.store")).result;              youtubeservice service = new youtubeservice(new youtubeservice.initializer()             {                 httpclientinitializer = credential,                 applicationname = "web"             });             if (service == null) throw new argumentnullexception("service");             return service;         }         catch (exception ex)         {             console.writeline(ex.innerexception);             return null;         }     } 

as can see in above code have handled youtube service throws exception because receives null value when host on server or iis on company network.but when run code locally(development machine) doesn't throw exception. have spent days solving issue no avail.any appreciated. exception message server error in '/' application. value cannot null. parameter name: youtubeservice description: unhandled exception occurred during execution of current web request. please review stack trace more information error , originated in code.

exception details: system.argumentnullexception: value cannot null. parameter name: youtubeservice


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -