Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. var fs = require('fs');
  2. var readline = require('readline');
  3. var {google} = require('googleapis');
  4. var OAuth2 = google.auth.OAuth2;
  5. let reply = {};
  6.  
  7.  
  8. module.exports.getinfo = async(bot) => {
  9. // If modifying these scopes, delete your previously saved credentials
  10. // at ~/.credentials/youtube-nodejs-quickstart.json
  11. var SCOPES = ['https://www.googleapis.com/auth/youtube.readonly'];
  12. var TOKEN_DIR = (process.env.HOME || process.env.HOMEPATH ||
  13. process.env.USERPROFILE) + '/.credentials/';
  14. var TOKEN_PATH = 'secrets/token.json';
  15.  
  16. // Load client secrets from a local file.
  17. fs.readFile('secrets/client_secret.json', function processClientSecrets(err, content) {
  18. if (err) {
  19. console.log('Error loading client secret file: ' + err);
  20. return;
  21. }
  22. // Authorize a client with the loaded credentials, then call the YouTube API.
  23. authorize(JSON.parse(content), loadup);
  24. });
  25.  
  26. /**
  27. * Create an OAuth2 client with the given credentials, and then execute the
  28. * given callback function.
  29. *
  30. * @param {Object} credentials The authorization client credentials.
  31. * @param {function} callback The callback to call with the authorized client.
  32. */
  33. function authorize(credentials, callback) {
  34. var clientSecret = credentials.installed.client_secret;
  35. var clientId = credentials.installed.client_id;
  36. var redirectUrl = credentials.installed.redirect_uris[0];
  37. var oauth2Client = new OAuth2(clientId, clientSecret, redirectUrl);
  38.  
  39. // Check if we have previously stored a token.
  40. fs.readFile(TOKEN_PATH, function(err, token) {
  41. if (err) {
  42. getNewToken(oauth2Client, callback);
  43. } else {
  44. oauth2Client.credentials = JSON.parse(token);
  45. callback(oauth2Client);
  46. }
  47. });
  48. }
  49.  
  50. function loadup(auth){
  51. //function
  52. var service = google.youtube('v3');
  53. bot.api = service;
  54. bot.apiauth = auth;
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement