Search code examples
node.jsgoogle-apiyoutube-apiyoutube-data-apigoogle-api-nodejs-client

Youtube nodejs API process response


I have managed to upload video to YouTube via google nodejs API. But I didnt figure out a way to get the url of the video which has been uploaded. When i log the the data which i get as response it seems like

{ status: 200,
  statusText: 'OK', 
  headers:  
   { 'x-guploader-uploadid': 'AEnB2UqicLz-FhD6KLtuvX_sZYeYQWuXoTM4FFusI6yCSGGlIdxKu3-EIneHhG04CYPqum1Uz8ISVmwIlzZqHrBJ2w-wOmbb6t5hEqOUrPnfRxirEd2tHfM',
 etag: '"_gJQceDMxJ8gP-8T2HLXUoURK8c/-WggxUHM10yHZDXznWuNSxlnSYU"',
 vary: 'Origin, X-Origin',
 'x-goog-correlation-id': 'zaYeqX5ngEo',
 'content-type': 'application/json; charset=UTF-8',
 'cache-control': 'no-cache, no-store, max-age=0, must-revalidate',
 pragma: 'no-cache',
 expires: 'Mon, 01 Jan 1990 00:00:00 GMT',
 date: 'Wed, 21 Feb 2018 15:19:39 GMT',
 'content-length': '975',
 server: 'UploadServer',
 'alt-svc': 'hq=":443"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337; quic=51303335,quic=":443"; ma=2592000; v="41,39,38,37,35"',
 connection: 'close' },
  config: 
   { adapter: [Function: httpAdapter],
     transformRequest: { '0': [Function: transformRequest] },
     transformResponse: { '0': [Function: transformResponse] },
     timeout: 0,
     xsrfCookieName: 'XSRF-TOKEN', 

cant see the full log as it was in server

Code for uploading the video is

              var yt = google.youtube('v3');
              yt.videos.insert({
                part: 'status,snippet',
                resource: {
                    snippet: {
                        title: "title",
                        description: "description"
                    },
                    status: { 
                        privacyStatus: 'public'
                    }
                },
                media: {
                    body: fs.createReadStream(file)
                }
            }, function(error, data){
                console.log(util.inspect(data, false, null));
                console.log(error);
                if(error){


                } else {

                }
              });

How can i get the uploaded video URL?


Solution

  • Got the solution. In cloud function the video object is present in the data key of the response. the video id will be response.data.id