Reputation: 137
I am trying to build my own endpoints inside of an App Engine Application. There is an endpoint API that needs to ask user for "https://www.googleapis.com/auth/drive.readonly" scope. It performs a list of the Drive API and scan the drive file of that user.
The problem is that I don't know how to make call to Drive api inside of an endpoint API.
I think inside of the endpoint method, it has the credentials we got from the user. But I don't know how to receive that.
I am using python as the backend language.
@drivetosp_test_api.api_class(resource_name='report')
class Report(remote.Service):
@endpoints.method(EmptyMessage, EmptyMessage,
name='generate',
path='report/generate',
http_method='GET'
)
def report_generate(self, request):
logging.info(endpoints)
return EmptyMessage()
Upvotes: 1
Views: 516
Reputation: 15569
You can use os.environ
to access the HTTP Authorization header, that includes the access token, that was granted all scopes you asked for on the client side, include drive.readonly
in your sample.
if "HTTP_AUTHORIZATION" in os.environ:
(tokentype, token) = os.environ["HTTP_AUTHORIZATION"].split(" ")
You can then use this token to make calls to the API, either directly or by using the Google APIs Client Library for Python:
credentials = AccessTokenCredentials(token, 'my-user-agent/1.0')
http = httplib2.Http()
http = credentials.authorize(http)
service = build('drive', 'v2', http=http)
files = service.files().list().execute()
Note that this approach won't work if you are using an Android client, because that uses ID-Token authorization instead of access tokens.
Upvotes: 1