Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var fs = require('fs');
- var readline = require('readline');
- var {google} = require('googleapis');
- var OAuth2 = google.auth.OAuth2;
- let reply = {};
- module.exports.getinfo = async(bot) => {
- // If modifying these scopes, delete your previously saved credentials
- // at ~/.credentials/youtube-nodejs-quickstart.json
- var SCOPES = ['https://www.googleapis.com/auth/youtube.readonly'];
- var TOKEN_DIR = (process.env.HOME || process.env.HOMEPATH ||
- process.env.USERPROFILE) + '/.credentials/';
- var TOKEN_PATH = 'secrets/token.json';
- // Load client secrets from a local file.
- fs.readFile('secrets/client_secret.json', function processClientSecrets(err, content) {
- if (err) {
- console.log('Error loading client secret file: ' + err);
- return;
- }
- // Authorize a client with the loaded credentials, then call the YouTube API.
- authorize(JSON.parse(content), loadup);
- });
- /**
- * Create an OAuth2 client with the given credentials, and then execute the
- * given callback function.
- *
- * @param {Object} credentials The authorization client credentials.
- * @param {function} callback The callback to call with the authorized client.
- */
- function authorize(credentials, callback) {
- var clientSecret = credentials.installed.client_secret;
- var clientId = credentials.installed.client_id;
- var redirectUrl = credentials.installed.redirect_uris[0];
- var oauth2Client = new OAuth2(clientId, clientSecret, redirectUrl);
- // Check if we have previously stored a token.
- fs.readFile(TOKEN_PATH, function(err, token) {
- if (err) {
- getNewToken(oauth2Client, callback);
- } else {
- oauth2Client.credentials = JSON.parse(token);
- callback(oauth2Client);
- }
- });
- }
- function loadup(auth){
- //function
- var service = google.youtube('v3');
- bot.api = service;
- bot.apiauth = auth;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement