google apis upload video to my youtube channel

Viewed 57

hope you all having a good day.

currently I am working with googleapis npm package with my Express server. I wanted to upload a video to my youtube channel. so I wrote some code with some help from here and there, I have it working but I got redirect to google's page to login first

here is my question, can I achieve the same result but without redirecting to google's page maybe with some api token, it always going to be this youtube channel and my own videos

here is what i already tried.

const { web: OAuth } = require("./credentials.json");
const { google } = require("googleapis");

const oAuth2Client = new google.auth.OAuth2(
  OAuth.client_id,
  OAuth.client_secret,
  OAuth.redirect_uris[0]
);

// i generate a url like this and redirect
const url = oAuth2Client.generateAuthUrl({
  access_type: "offline",
  scope: SCOPES,
});

const youtube = google.youtube({ version: "v3", auth: oAuth2Client });

youtube.videos.insert(
  {
    resource: {
      snippet: {
        title: "title",
        description: "description",
        tags: "tags",
      },
      status: {
        privacyStatus: "private",
      },
    },
    part: "snippet,status",
    media: {
      body: fs.createReadStream(file), // assume that i have a file
    },
  },
  (err, data) => {
    if (err) {
      res.send(err);
      console.log(err);
      return;
    }
    console.log(data);
    console.log("Done.");
  }
);

I've gone through the docs, it's a very mess

can i possibly do that?

0 Answers
Related