11var fs = require ( 'fs' ) ;
22var readline = require ( 'readline' ) ;
3- var google = require ( 'googleapis' ) ;
4- var googleAuth = require ( ' google- auth-library' ) ;
3+ var { google} = require ( 'googleapis' ) ;
4+ var OAuth2 = google . auth . OAuth2 ;
55
66// If modifying these scopes, delete your previously saved credentials
77// at ~/.credentials/youtube-nodejs-quickstart.json
@@ -31,8 +31,7 @@ function authorize(credentials, callback) {
3131 var clientSecret = credentials . installed . client_secret ;
3232 var clientId = credentials . installed . client_id ;
3333 var redirectUrl = credentials . installed . redirect_uris [ 0 ] ;
34- var auth = new googleAuth ( ) ;
35- var oauth2Client = new auth . OAuth2 ( clientId , clientSecret , redirectUrl ) ;
34+ var oauth2Client = new OAuth2 ( clientId , clientSecret , redirectUrl ) ;
3635
3736 // Check if we have previously stored a token.
3837 fs . readFile ( TOKEN_PATH , function ( err , token ) {
@@ -90,7 +89,10 @@ function storeToken(token) {
9089 throw err ;
9190 }
9291 }
93- fs . writeFile ( TOKEN_PATH , JSON . stringify ( token ) ) ;
92+ fs . writeFile ( TOKEN_PATH , JSON . stringify ( token ) , ( err ) => {
93+ if ( err ) throw err ;
94+ console . log ( 'Token stored to ' + TOKEN_PATH ) ;
95+ } ) ;
9496 console . log ( 'Token stored to ' + TOKEN_PATH ) ;
9597}
9698
@@ -110,7 +112,7 @@ function getChannel(auth) {
110112 console . log ( 'The API returned an error: ' + err ) ;
111113 return ;
112114 }
113- var channels = response . items ;
115+ var channels = response . data . items ;
114116 if ( channels . length == 0 ) {
115117 console . log ( 'No channel found.' ) ;
116118 } else {
0 commit comments