Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.

Commit bc3e6df

Browse files
author
Eric Koleda
committed
Add Trello sample.
1 parent c0f66de commit bc3e6df

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

samples/Trello.gs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
var CONSUMER_KEY = '...';
2+
var CONSUMER_SECRET = '...';
3+
4+
/**
5+
* Authorizes and makes a request to the Trello API.
6+
*/
7+
function run() {
8+
var service = getService();
9+
if (service.hasAccess()) {
10+
var url = 'https://api.trello.com/1/members/me/boards';
11+
var response = service.fetch(url);
12+
var result = JSON.parse(response.getContentText());
13+
Logger.log(JSON.stringify(result, null, 2));
14+
} else {
15+
var authorizationUrl = service.authorize();
16+
Logger.log('Open the following URL and re-run the script: %s',
17+
authorizationUrl);
18+
}
19+
}
20+
21+
/**
22+
* Reset the authorization state, so that it can be re-tested.
23+
*/
24+
function reset() {
25+
var service = getService();
26+
service.reset();
27+
}
28+
29+
/**
30+
* Configures the service.
31+
*/
32+
function getService() {
33+
return OAuth1.createService('Trello')
34+
// Set the endpoint URLs.
35+
.setRequestTokenUrl('https://trello.com/1/OAuthGetRequestToken')
36+
.setAuthorizationUrl('https://trello.com/1/OAuthAuthorizeToken')
37+
.setAccessTokenUrl('https://trello.com/1/OAuthGetAccessToken')
38+
39+
// Set the consumer key and secret.
40+
.setConsumerKey(CONSUMER_KEY)
41+
.setConsumerSecret(CONSUMER_SECRET)
42+
43+
// Set the name of the callback function in the script referenced
44+
// above that should be invoked to complete the OAuth flow.
45+
.setCallbackFunction('authCallback')
46+
47+
// Set the property store where authorized tokens should be persisted.
48+
.setPropertyStore(PropertiesService.getUserProperties());
49+
}
50+
51+
/**
52+
* Handles the OAuth2 callback.
53+
*/
54+
function authCallback(request) {
55+
var service = getService();
56+
var authorized = service.handleCallback(request);
57+
if (authorized) {
58+
return HtmlService.createHtmlOutput('Success!');
59+
} else {
60+
return HtmlService.createHtmlOutput('Denied');
61+
}
62+
}

0 commit comments

Comments
 (0)