-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquickstart.js
36 lines (32 loc) · 1.17 KB
/
quickstart.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var googleapis = require('googleapis'),
readline = require('readline');
var CLIENT_ID = '994002661940-acjr0668hkji9kf2rqjnbtfvllujk7fv.apps.googleusercontent.com',
CLIENT_SECRET = 'FzP586LkRBxCqurbH3Tw7YPT',
REDIRECT_URL = 'http://localhost:3000/redirect',
SCOPE = 'https://www.googleapis.com/auth/drive.file';
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
var auth = new googleapis.OAuth2Client(CLIENT_ID, CLIENT_SECRET, REDIRECT_URL);
googleapis.discover('drive', 'v2').execute(function(err, client) {
var url = auth.generateAuthUrl({ scope: SCOPE });
var getAccessToken = function(code) {
auth.getToken(code, function(err, tokens) {
if (err) {
console.log('Error while trying to retrieve access token', err);
return;
}
auth.credentials = tokens;
upload();
});
};
var upload = function() {
client.drive.files
.insert({ title: 'My Document', mimeType: 'text/plain' })
.withMedia('text/plain', 'Hello World!')
.withAuthClient(auth).execute(console.log);
};
console.log('Visit the url: ', url);
rl.question('Enter the code here:', getAccessToken);
});