Authenticate Youtube API on a Worker process C# -


i'm running process without ui retrieves uploaded videos youtube. on develpement machine authenticates on user behalf , works.

the problem when process running on server: browser window doesn't fire user let use account (it should require once).

event viewer shows no errors whatsoever. service accounts doesn't seem work youtube, api key less permissions , oath way authenticate , broadcasted videos. or wrong?

so question is: how run service single user , retrieve videos without ui?

         private async task run()                 {                      try                     {                         usercredential credential;                         using (var stream = new filestream(startpath + "\\client_secrets.json", filemode.open, fileaccess.read))                         {                              credential = await googlewebauthorizationbroker.authorizeasync(                                 googleclientsecrets.load(stream).secrets,                                 new[] { youtubeservice.scope.youtubereadonly, youtubeservice.scope.youtube  },                                 "user",                                 cancellationtoken.none,                                 new filedatastore("store")                             );                         }                          var youtubeservice = new youtubeservice(new baseclientservice.initializer()                         {                             httpclientinitializer = credential,                             applicationname = this.gettype().tostring()                         });     ....                  } 

i have tried:

 string serviceaccountemail = "e-mail";              var certificate = new x509certificate2(hostingenvironment.mappath("~/content/key.p12"), "notasecret", x509keystorageflags.exportable);              serviceaccountcredential credential = new serviceaccountcredential(                new serviceaccountcredential.initializer(serviceaccountemail)               {                    scopes = new[] { youtubeservice.scope.youtube, youtubeservice.scope.youtubepartnerchannelaudit, youtubeservice.scope.youtubeupload }                }.fromcertificate(certificate));             var youtubeservice = new youtubeservice(new baseclientservice.initializer()             {                 httpclientinitializer = credential,                 applicationname = "api",             }); 

the youtube data api lets incorporate functions executed on youtube website own website or application. lists below identify different types of resources can retrieve using api. api supports methods insert, update, or delete many of these resources.

this reference guide explains how use api perform of these operations. guide organized resource type. resource represents type of item comprises part of youtube experience, such video, playlist, or subscription. each resource type, guide lists 1 or more data representations, , resources represented json objects. guide lists 1 or more supported methods (list, post, delete, etc.) each resource type , explains how use methods in application.

the following requirements apply youtube data api requests:

  • every request must either specify api key (with key parameter) or provide oauth 2.0 token. api key available in developer console's api access pane project.

  • you must send authorization token every insert, update, , delete request. must send authorization token request retrieves authenticated user's private data.

in addition, api methods retrieving resources may support parameters require authorization or may contain additional metadata when requests authorized. example, request retrieve user's uploaded videos may contain private videos if request authorized specific user.

  • the api supports oauth 2.0 authentication protocol. can provide oauth 2.0 token in either of following ways:

  • use access_token query parameter this: ?access_token=oauth2-token

  • use http authorization header this: authorization: bearer oauth2-token complete instructions implementing oauth 2.0 authentication in application can found in authentication guide.

Comments