|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 | # [START all] |
15 | | -"""Sample appengine app demonstrating 3-legged oauth.""" |
| 15 | + |
| 16 | +""" |
| 17 | +Sample App Engine application that demonstrates authentication to BigQuery |
| 18 | +using User OAuth2 as opposed to OAuth2 Service Accounts. |
| 19 | +
|
| 20 | +For more information about BigQuery, see README.md under /bigquery. |
| 21 | +For more information about App Engine, see README.md under /appengine. |
| 22 | +""" |
| 23 | + |
16 | 24 | import json |
17 | 25 | import os |
18 | 26 |
|
19 | 27 | from googleapiclient.discovery import build |
20 | | - |
21 | 28 | from oauth2client.appengine import OAuth2DecoratorFromClientSecrets |
22 | | - |
23 | 29 | import webapp2 |
24 | 30 |
|
25 | 31 |
|
26 | 32 | # The project id whose datasets you'd like to list |
27 | | -PROJECTID = '<myproject_id>' |
| 33 | +PROJECTID = '<your-project-id>' |
28 | 34 |
|
29 | 35 | # Create the method decorator for oauth. |
30 | 36 | decorator = OAuth2DecoratorFromClientSecrets( |
|
37 | 43 |
|
38 | 44 | class MainPage(webapp2.RequestHandler): |
39 | 45 |
|
| 46 | + # oauth_required ensures that the user goes through the OAuth2 |
| 47 | + # authorization flow before reaching this handler. |
40 | 48 | @decorator.oauth_required |
41 | 49 | def get(self): |
42 | | - """Lists the datasets in PROJECTID""" |
| 50 | + # This is an httplib2.Http instance that is signed with the user's |
| 51 | + # credentials. This allows you to access the BigQuery API on behalf |
| 52 | + # of the user. |
43 | 53 | http = decorator.http() |
44 | | - datasets = service.datasets() |
45 | 54 |
|
46 | | - response = datasets.list(projectId=PROJECTID).execute(http) |
| 55 | + response = service.datasets().list(projectId=PROJECTID).execute(http) |
47 | 56 |
|
48 | 57 | self.response.out.write('<h3>Datasets.list raw response:</h3>') |
49 | 58 | self.response.out.write('<pre>%s</pre>' % |
50 | 59 | json.dumps(response, sort_keys=True, indent=4, |
51 | 60 | separators=(',', ': '))) |
52 | 61 |
|
53 | 62 |
|
54 | | -# Create the webapp2 application |
55 | 63 | app = webapp2.WSGIApplication([ |
56 | 64 | ('/', MainPage), |
57 | 65 | # Create the endpoint to receive oauth flow callbacks |
|
0 commit comments