|
24 | 24 | import httplib2
|
25 | 25 | from oauth2client.client import GoogleCredentials
|
26 | 26 |
|
27 |
| - |
| 27 | +# TODO REMOVE - when discovery is public |
| 28 | +GOOGLE_API_KEY = "GOOGLE_API_KEY" |
| 29 | + |
| 30 | +# TODO REMOVE - when discovery is public |
| 31 | +DISCOVERY_URL = ('https://language.googleapis.com/$discovery/rest?' |
| 32 | + 'version=v1&labels=GOOGLE_INTERNAL&key={}') |
| 33 | + |
| 34 | +# TODO UNCOMMENT - when discovery is public |
| 35 | +# def get_service(): |
| 36 | +# credentials = GoogleCredentials.get_application_default() |
| 37 | +# scoped_credentials = credentials.create_scoped( |
| 38 | +# ['https://www.googleapis.com/auth/cloud-platform']) |
| 39 | +# http = httplib2.Http() |
| 40 | +# scoped_credentials.authorize(http) |
| 41 | +# return discovery.build('language', 'v1', http=http) |
| 42 | +# TODO END |
| 43 | + |
| 44 | +# TODO REMOVE - when discovery is public |
28 | 45 | def get_service():
|
| 46 | + """Get language service using discovery.""" |
| 47 | + import os |
| 48 | + api_key = os.environ[GOOGLE_API_KEY] |
29 | 49 | credentials = GoogleCredentials.get_application_default()
|
30 |
| - scoped_credentials = credentials.create_scoped( |
31 |
| - ['https://www.googleapis.com/auth/cloud-platform']) |
32 |
| - http = httplib2.Http() |
33 |
| - scoped_credentials.authorize(http) |
34 |
| - return discovery.build('language', 'v1beta1', http=http) |
35 |
| - |
| 50 | + service = discovery.build('language', 'v1', http=httplib2.Http(), credentials=credentials, |
| 51 | + discoveryServiceUrl=DISCOVERY_URL.format(api_key)) |
| 52 | + return service |
| 53 | +# TODO END |
36 | 54 |
|
37 | 55 | def get_native_encoding_type():
|
38 | 56 | """Returns the encoding type that matches Python's native strings."""
|
|
0 commit comments