1+ /**
2+ * Extend your community - Meetup. Meetup API
3+ * http://www.meetup.com/meetup_api/
4+ * http://www.meetup.com/meetup_api/auth/#oauth2
5+ */
6+
7+ var CLIENT_ID = '...' ;
8+ var CLIENT_SECRET = '...' ;
9+
10+ /**
11+ * Authorizes and makes a request to the Meetup API.
12+ */
13+
14+ function run ( ) {
15+ var service = getService ( ) ;
16+ if ( service . hasAccess ( ) ) {
17+ var url = 'https://api.meetup.com/dashboard' ;
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+ var service = getService ( ) ;
37+ service . reset ( ) ;
38+ }
39+
40+ /**
41+ * Configures the service.
42+ */
43+ function getService ( ) {
44+ return OAuth2 . createService ( 'Meetup' )
45+ // Set the endpoint URLs.
46+ . setAuthorizationBaseUrl ( 'https://secure.meetup.com/oauth2/authorize' )
47+ . setTokenUrl ( 'https://secure.meetup.com/oauth2/access' )
48+
49+ // Set the client ID and secret.
50+ . setClientId ( CLIENT_ID )
51+ . setClientSecret ( CLIENT_SECRET )
52+
53+ // Set the name of the callback function that should be invoked to complete
54+ // the OAuth flow.
55+ . setCallbackFunction ( 'authCallback' )
56+
57+ // Set the property store where authorized tokens should be persisted.
58+ . setPropertyStore ( PropertiesService . getUserProperties ( ) ) ;
59+ }
60+
61+ /**
62+ * Handles the OAuth callback.
63+ */
64+ function authCallback ( request ) {
65+ var service = getService ( ) ;
66+ var authorized = service . handleCallback ( request ) ;
67+ if ( authorized ) {
68+ return HtmlService . createHtmlOutput ( 'Success!' ) ;
69+ } else {
70+ return HtmlService . createHtmlOutput ( 'Denied' ) ;
71+ }
72+ }
0 commit comments