How to use googleapis

Comprehensive googleapis code examples:

How to use googleapis.gmail:

0
1
2
3
4
5
6
7
8
9
var fs = require('fs');
var path = require('path');
var _ = require('underscore');
var googleapis = require('googleapis');
var directory = googleapis.admin('directory_v1');
var gmail = googleapis.gmail('v1');
var walk = require('fs-walk');
var Q = require('q');
var levelup = require('levelup')
var util = require('util');

How to use googleapis.admin:

How to use googleapis.classroom:

22
23
24
25
26
27
28
29
30
31
//getting Google Token from DB
const userFromDB = await User.findById(req.user._id);
oauth2Client.credentials = userFromDB.googleTokens;

//getting students from that course from Google Classroom
const classroom = google.classroom({ version: "v1", auth: oauth2Client });
const resFromG = await classroom.courses.students.list({
  courseId: req.body.id,
});
const students = resFromG.data.students;

How to use googleapis.oauth2:

14
15
16
17
18
19
20
21
22
23
if (req.body.googleAccessToken) {
  const { googleAccessToken } = req.body;

  var oauth2Client = new OAuth2();
  oauth2Client.setCredentials({ access_token: googleAccessToken });
  var oauth2 = google.oauth2({
    auth: oauth2Client,
    version: "v2",
  });
  let { data } = await oauth2.userinfo.get();

How to use googleapis.OAuth2Client:

How to use googleapis.urlshortener:

93
94
95
96
97
98
99
100
101
102
Example: Creates a URL Shortener client and retrieves the long url of the
given short url:

``` js
var google = require('googleapis');
var urlshortener = google.urlshortener('v1');

var params = { shortUrl: 'http://goo.gl/xKbRu3' };

// get the long url of a shortened url

How to use googleapis.discover:

27
28
29
30
31
32
33
34
35
36
var self = this,
  exports = {},
  log = this.$resource.log,
  pod = this.pod;

gapi.discover('drive', 'v2').execute(function(err, client) {
  var auth = self.pod.getOAuthClient(sysImports);
  for (var i = 0; i < contentParts._files.length; i++) {
    (function(file) {
      $resource.file.get(file.localpath, function(err, buffer) {

How to use googleapis.calendar:

2
3
4
5
6
7
8
9
10
11
12


class GoogleCal {
  constructor(configuration) {
    this.configuration = configuration;
    this.scopes = ['https://www.googleapis.com/auth/calendar.readonly'];
    this.googleCal = google.calendar({
      version: 'v3',
      auth: this.configuration.GOOGLE_CALENDAR_API_KEY,
    });
  }

How to use googleapis.sheets:

How to use googleapis.youtube:

9
10
11
12
13
14
15
16
17
18
];
var TOKEN_DIR = '.credentials/';
var TOKEN_PATH = TOKEN_DIR + 'youtube-credentials.json';

var _config = null;
var _youtube = google.youtube('v3');
var _liveChatId = '';
var _isReady = false;
var _lastCheckTime = new Date().getTime();
var _auth = null;

How to use googleapis.plus:

How to use googleapis.drive:

43
44
45
46
47
48
49
50
51
52
    })
  }
}

function getPictureFolder (cb) {
  var drive = Google.drive('v3')
  drive.files.list({
    q: "mimeType='application/vnd.google-apps.folder' and name = 'Camera Pictures'",
    fields: 'nextPageToken, files(id, name)',
    spaces: 'drive',

How to use googleapis.youtube_v3:

6
7
8
9
10
11
12
13
14
15
16
17
// const ItemModel = dbConnection.model('item', itemSchema)


// For multiple Google API keys, please specify as a single string separated by ` | `
// const authKeys = process.env.GOOGLE_API_KEY.split(' | ')
const authKeys = ['AIzaSyA5QUpisu9mTFTADHcOu_GG4lI5nlEEBO4', 'AIzaSyA5QUpisu9mTFTADHcOu_GG4lI5nlEEBO4']
let gapi = new googleapis.youtube_v3.Youtube({
  auth: authKeys.shift() // Pop and take the first element in an array, when exhausted shift to next, and so on
})


// We fetch results only after 2019-01-01 to avoud old results

How to use googleapis.auth:

How to use googleapis.google:

18
19
20
21
22
23
24
25
26
27
constructor(actionInstance, log) {
    this.actionInstance = actionInstance;
    this.log = log;
}
makeOAuthClient(redirectUri) {
    return new googleapis_1.google.auth.OAuth2(this.actionInstance.oauthClientId, this.actionInstance.oauthClientSecret, redirectUri);
}
makeLoginForm(request) {
    return __awaiter(this, void 0, void 0, function* () {
        // Step 0 in the outh flow - generate an *ActionHub* url that user can visit to kick things off