Skip to content

Commit bcad494

Browse files
author
Eric Koleda
committed
Adding sample for Zoom.
1 parent 80b06f3 commit bcad494

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

samples/Zoom.gs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* This sample demonstrates how to configure the library for the Zoom API, using
3+
* a User Managed App. Instructions on how to generate OAuth credentuals is
4+
* available here:
5+
* https://marketplace.zoom.us/docs/guides/authorization/oauth-with-zoom
6+
*/
7+
8+
var CLIENT_ID = '...';
9+
var CLIENT_SECRET = '...';
10+
11+
/**
12+
* Authorizes and makes a request to the Zoom API.
13+
*/
14+
function run() {
15+
var service = getService();
16+
if (service.hasAccess()) {
17+
var url = 'https://api.zoom.us/v2/users/me';
18+
var response = UrlFetchApp.fetch(url, {
19+
headers: {
20+
Authorization: 'Bearer ' + service.getAccessToken()
21+
}
22+
});
23+
var result = JSON.parse(response.getContentText());
24+
Logger.log(JSON.stringify(result, null, 2));
25+
} else {
26+
var authorizationUrl = service.getAuthorizationUrl();
27+
Logger.log('Open the following URL and re-run the script: %s',
28+
authorizationUrl);
29+
}
30+
}
31+
32+
/**
33+
* Reset the authorization state, so that it can be re-tested.
34+
*/
35+
function reset() {
36+
getService().reset();
37+
}
38+
39+
/**
40+
* Configures the service.
41+
*/
42+
function getService() {
43+
return OAuth2.createService('Zoom')
44+
// Set the endpoint URLs.
45+
.setAuthorizationBaseUrl('https://zoom.us/oauth/authorize')
46+
.setTokenUrl('https://zoom.us/oauth/token')
47+
48+
// Set the client ID and secret.
49+
.setClientId(CLIENT_ID)
50+
.setClientSecret(CLIENT_SECRET)
51+
52+
// Set the name of the callback function that should be invoked to
53+
// complete the OAuth flow.
54+
.setCallbackFunction('authCallback')
55+
56+
// Set the property store where authorized tokens should be persisted.
57+
.setPropertyStore(PropertiesService.getUserProperties())
58+
59+
// Set the required scopes:
60+
// https://marketplace.zoom.us/docs/guides/zoom-app-marketplace/permissions#user-managed-app-scopes
61+
.setScope('user:read')
62+
63+
// Set the Authorization header for token requests.
64+
// https://marketplace.zoom.us/docs/guides/authorization/oauth-with-zoom#step-3-exchange-the-authorization-code-for-an-access-token
65+
.setTokenHeaders({
66+
'Authorization': 'Basic ' +
67+
Utilities.base64Encode(CLIENT_ID + ':' + CLIENT_SECRET),
68+
});
69+
}
70+
71+
/**
72+
* Handles the OAuth callback.
73+
*/
74+
function authCallback(request) {
75+
var service = getService();
76+
var authorized = service.handleCallback(request);
77+
if (authorized) {
78+
return HtmlService.createHtmlOutput('Success!');
79+
} else {
80+
return HtmlService.createHtmlOutput('Denied.');
81+
}
82+
}
83+
84+
/**
85+
* Logs the redict URI to register.
86+
*/
87+
function logRedirectUri() {
88+
Logger.log(getService().getRedirectUri());
89+
}

0 commit comments

Comments
 (0)