@@ -32,13 +32,15 @@ const url = require('url');
3232const open = require ( 'open' ) ;
3333const destroyer = require ( 'server-destroy' ) ;
3434
35- // Reads the secrets from a `keys.json` file, which should be downloaded from
36- // the Google Developers Console and saved in the same directory with the sample
37- // app.
35+ // Reads the secrets from a `oauth2. keys.json` file, which should be downloaded
36+ // from the Google Developers Console and saved in the same directory with the
37+ // sample app.
3838// eslint-disable-next-line node/no-unpublished-require
3939// eslint-disable-next-line node/no-missing-require, node/no-unpublished-require
4040const keys = require ( './oauth2.keys.json' ) ;
4141
42+ // This sample app only calls read-only methods from the Admin API. Include
43+ // additional scopes if calling methods that modify the configuration.
4244const SCOPES = [ 'https://www.googleapis.com/auth/analytics.readonly' ] ;
4345
4446async function listAccounts ( authClient ) {
@@ -73,13 +75,12 @@ function getAuthenticatedClient() {
7375 const oAuth2Client = new OAuth2Client (
7476 keys . web . client_id ,
7577 keys . web . client_secret ,
76- // The first redirect URL from the `keys.json` file will be used to
77- // generate the OAuth2 callback URL. Update the line below or edit the
78- // redirect URL in the Google Developers Console if needed.
78+ // The first redirect URL from the `oauth2. keys.json` file will be used
79+ // to generate the OAuth2 callback URL. Update the line below or edit
80+ // the redirect URL in the Google Developers Console if needed.
7981 // This sample app expects the callback URL to be
8082 // 'http://localhost:3000/oauth2callback'
81- //keys.web.redirect_uris[0]
82- 'http://ikuleshov.mtv.corp.google.com:3000/oauth2callback'
83+ keys . web . redirect_uris [ 0 ]
8384 ) ;
8485
8586 // Generate the url that will be used for the consent dialog.
@@ -88,13 +89,14 @@ function getAuthenticatedClient() {
8889 scope : SCOPES . join ( ' ' ) ,
8990 } ) ;
9091
91- // Open an http server to accept the oauth callback. In this simple example, the
92+ // Open an http server to accept the oauth callback. In this example, the
9293 // only request to our webserver is to /oauth2callback?code=<code>
9394 const server = http
9495 . createServer ( async ( req , res ) => {
9596 try {
9697 if ( req . url . indexOf ( '/oauth2callback' ) > - 1 ) {
97- // acquire the code from the querystring, and close the web server.
98+ // Acquire the code from the querystring, and close the web
99+ // server.
98100 const qs = new url . URL ( req . url , 'http://localhost:3000' )
99101 . searchParams ;
100102 const code = qs . get ( 'code' ) ;
@@ -129,7 +131,6 @@ async function main() {
129131 getAuthenticatedClient ( ) . then ( authClient => listAccounts ( authClient ) ) ;
130132}
131133
132- main ( ) . catch ( console . error ) ;
133134main ( ...process . argv . slice ( 2 ) ) . catch ( err => {
134135 console . error ( err . message ) ;
135136 process . exitCode = 1 ;
0 commit comments