Socket
Socket
Sign inDemoInstall

youtube-api

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

youtube-api - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

example/credentials.json

103

example/index.js

@@ -1,33 +0,84 @@

// Dependencies
var Youtube = require("../lib");
/**
* This script uploads a video (specifically `video.mp4` from the current
* directory) to YouTube,
*
* To run this script you have to create OAuth2 credentials and download them
* as JSON and replace the `credentials.json` file. Then install the
* dependencies:
*
* npm i r-json lien opn bug-killer
*
* Don't forget to run an `npm i` to install the `youtube-api` dependencies.
* */
// Authenticate using an access token
Youtube.authenticate({
type: "oauth"
, token: "your access token"
// Depende3ncies
var Youtube = require("../lib")
, Fs = require("fs")
, ReadJson = require("r-json")
, Lien = require("lien")
, Logger = require("bug-killer")
, Opn = require("opn")
;
// Constants
// I downloaded the file from OAuth2 -> Download JSON
const CREDENTIALS = ReadJson("./credentials.json");
// Init lien server
var server = new Lien({
host: "localhost"
, port: 5000
});
// List your subcribers
Youtube.subscriptions.list({
"part": "id"
, "mySubscribers": true
, "maxResults": 50
}, function (err, data) {
console.log(err || data);
var stdIn = ReadLine.createInterface({
input: process.stdin
, output: process.stdout
});
// Add a Video to a playlist
Youtube.playlistItems.insert({
"part": "snippet"
, "resource": {
"snippet": {
"playlistId": "YouTube Playlist ID"
, "resourceId": {
"kind" : "youtube#video"
, "videoId" : "YouTube Video ID"
// Authenticate
// You can access the Youtube resources via OAuth2 only.
// https://developers.google.com/youtube/v3/guides/moving_to_oauth#service_accounts
var oauth = Youtube.authenticate({
type: "oauth"
, client_id: CREDENTIALS.web.client_id
, client_secret: CREDENTIALS.web.client_secret
, redirect_url: CREDENTIALS.web.redirect_uris[0]
});
Opn(oauth.generateAuthUrl({
access_type: "offline"
, scope: ["https://www.googleapis.com/auth/youtube.upload"]
}));
// Handle oauth2 callback
server.page.add("/oauth2callback", function (lien) {
Logger.log("Trying to get the token using the following code: " + lien.search.code);
oauth.getToken(lien.search.code, function(err, tokens) {
if (err) { lien(err, 400); return Logger.log(err); }
oauth.setCredentials(tokens);
Youtube.videos.insert({
resource: {
// Video title and description
snippet: {
title: "Testing YoutTube API NodeJS module"
, description: "Test video upload via YouTube API"
}
// I don't want to spam my subscribers
, status: {
privacyStatus: "private"
}
}
}
}
}, function (err, data) {
console.log(err || data);
// This is for the callback function
, part: "snippet,status"
// Create the readable stream to upload the video
, media: {
body: Fs.createReadStream("video.mp4")
}
}, function (err, data) {
if (err) { return lien.end(err, 400); }
lien.end(data);
});
});
});
{
"name": "youtube-api",
"version": "1.0.0",
"version": "1.0.1",
"description": "A Node.JS module, which provides an object oriented wrapper for the Youtube v3 API.",

@@ -39,2 +39,2 @@ "main": "lib/index.js",

}
}
}

@@ -34,34 +34,84 @@ <!---------------------------------------------------------------------------->

```js
// Dependencies
var Youtube = require("youtube-api");
/**
* This script uploads a video (specifically `video.mp4` from the current
* directory) to YouTube,
*
* To run this script you have to create OAuth2 credentials and download them
* as JSON and replace the `credentials.json` file. Then install the
* dependencies:
*
* npm i r-json lien opn bug-killer
*
* Don't forget to run an `npm i` to install the `youtube-api` dependencies.
* */
// Authenticate using an access token
Youtube.authenticate({
type: "oauth"
, token: "your access token"
// Depende3ncies
var Youtube = require("youtube-api")
, Fs = require("fs")
, ReadJson = require("r-json")
, Lien = require("lien")
, Logger = require("bug-killer")
, Opn = require("opn")
;
// Constants
// I downloaded the file from OAuth2 -> Download JSON
const CREDENTIALS = ReadJson("./credentials.json");
// Init lien server
var server = new Lien({
host: "localhost"
, port: 5000
});
// List your subcribers
Youtube.subscriptions.list({
"part": "id"
, "mySubscribers": true
, "maxResults": 50
}, function (err, data) {
console.log(err || data);
var stdIn = ReadLine.createInterface({
input: process.stdin
, output: process.stdout
});
// Add a Video to a playlist
Youtube.playlistItems.insert({
"part": "snippet"
, "resource": {
"snippet": {
"playlistId": "YouTube Playlist ID"
, "resourceId": {
"kind" : "youtube#video"
, "videoId" : "YouTube Video ID"
// Authenticate
// You can access the Youtube resources via OAuth2 only.
// https://developers.google.com/youtube/v3/guides/moving_to_oauth#service_accounts
var oauth = Youtube.authenticate({
type: "oauth"
, client_id: CREDENTIALS.web.client_id
, client_secret: CREDENTIALS.web.client_secret
, redirect_url: CREDENTIALS.web.redirect_uris[0]
});
Opn(oauth.generateAuthUrl({
access_type: "offline"
, scope: ["https://www.googleapis.com/auth/youtube.upload"]
}));
// Handle oauth2 callback
server.page.add("/oauth2callback", function (lien) {
Logger.log("Trying to get the token using the following code: " + lien.search.code);
oauth.getToken(lien.search.code, function(err, tokens) {
if (err) { lien(err, 400); return Logger.log(err); }
oauth.setCredentials(tokens);
Youtube.videos.insert({
resource: {
// Video title and description
snippet: {
title: "Testing YoutTube API NodeJS module"
, description: "Test video upload via YouTube API"
}
// I don't want to spam my subscribers
, status: {
privacyStatus: "private"
}
}
}
}
}, function (err, data) {
console.log(err || data);
// This is for the callback function
, part: "snippet,status"
// Create the readable stream to upload the video
, media: {
body: Fs.createReadStream("video.mp4")
}
}, function (err, data) {
if (err) { return lien.end(err, 400); }
lien.end(data);
});
});
});

@@ -68,0 +118,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc