|
22 | 22 | from apiclient import errors |
23 | 23 | from apiclient.discovery import build |
24 | 24 | from httplib2 import Http |
25 | | -from oauth2client import file, client, tools |
| 25 | +from oauth2client import file as oauthfile, client, tools |
26 | 26 |
|
27 | 27 | # Setup the Apps Script API |
28 | 28 | SCOPES = 'https://www.googleapis.com/auth/script.projects' |
29 | | -store = file.Storage('token.json') |
| 29 | +store = oauthfile.Storage('token.json') |
30 | 30 | creds = store.get() |
31 | 31 | if not creds or creds.invalid: |
32 | 32 | flow = client.flow_from_clientsecrets('credentials.json', SCOPES) |
|
35 | 35 |
|
36 | 36 | # Call the Apps Script API |
37 | 37 | try: |
38 | | - # Create a new project |
39 | | - request = {'title2': 'My Script'} |
40 | | - response = service.projects().create(body=request).execute() |
| 38 | + # Create a new project |
| 39 | + request = {'title2': 'My Script'} |
| 40 | + response = service.projects().create(body=request).execute() |
41 | 41 |
|
42 | | - # Upload two files to the project |
43 | | - request = { |
44 | | - 'files': [{ |
45 | | - 'name': 'hello', |
46 | | - 'type': 'SERVER_JS', |
47 | | - 'source': 'function helloWorld() {\n console.log("Hello, world!");\n}' |
48 | | - }, { |
49 | | - 'name': 'appsscript', |
50 | | - 'type': 'JSON', |
51 | | - 'source': '{\"timeZone\":\"America/New_York\",\"exceptionLogging\":' + \ |
52 | | - '\"CLOUD\"}' |
53 | | - }] |
54 | | - } |
55 | | - response = service.projects().updateContent(body=request, |
| 42 | + # Upload two files to the project |
| 43 | + request = { |
| 44 | + 'files': [{ |
| 45 | + 'name': 'hello', |
| 46 | + 'type': 'SERVER_JS', |
| 47 | + 'source': 'function helloWorld() {\n ' \ |
| 48 | + 'console.log("Hello, world!");\n}' |
| 49 | + }, { |
| 50 | + 'name': 'appsscript', |
| 51 | + 'type': 'JSON', |
| 52 | + 'source': '{\"timeZone\":\"America/New_York\",' \ |
| 53 | + '\"exceptionLogging\":\"CLOUD\"}' |
| 54 | + }] |
| 55 | + } |
| 56 | + response = service.projects().updateContent(body=request, |
56 | 57 | scriptId=response['scriptId']).execute() |
57 | | - print('https://script.google.com/d/' + response['scriptId'] + '/edit') |
| 58 | + print('https://script.google.com/d/' + response['scriptId'] + '/edit') |
58 | 59 | except errors.HttpError as e: |
59 | | - # The API encountered a problem. |
60 | | - print(e.content) |
| 60 | + # The API encountered a problem. |
| 61 | + print(e.content) |
61 | 62 | # [END apps_script_quickstart] |
0 commit comments