1
1
var fs = require ( 'fs' ) ;
2
2
var 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 ;
5
5
6
6
// If modifying these scopes, delete your previously saved credentials
7
7
// at ~/.credentials/youtube-nodejs-quickstart.json
@@ -31,8 +31,7 @@ function authorize(credentials, callback) {
31
31
var clientSecret = credentials . installed . client_secret ;
32
32
var clientId = credentials . installed . client_id ;
33
33
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 ) ;
36
35
37
36
// Check if we have previously stored a token.
38
37
fs . readFile ( TOKEN_PATH , function ( err , token ) {
@@ -90,7 +89,10 @@ function storeToken(token) {
90
89
throw err ;
91
90
}
92
91
}
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
+ } ) ;
94
96
console . log ( 'Token stored to ' + TOKEN_PATH ) ;
95
97
}
96
98
@@ -110,7 +112,7 @@ function getChannel(auth) {
110
112
console . log ( 'The API returned an error: ' + err ) ;
111
113
return ;
112
114
}
113
- var channels = response . items ;
115
+ var channels = response . data . items ;
114
116
if ( channels . length == 0 ) {
115
117
console . log ( 'No channel found.' ) ;
116
118
} else {
0 commit comments