我正在开发使用Python编写并使用Endpoints API的Google App Engine应用程序.与此同时,我正在编写Chrome扩展程序以与Endpoints API进行交互.我一直在使用Endpoints API和授权遇到很多问题.目前,这是我的设置:
from google.appengine.ext import endpoints
from protorpc import message_types
from protorpc import remote
ALLOWED_CLIENT_IDS = ['client_id_from_google_api_console',
endpoints.API_EXPLORER_CLIENT_ID]
@endpoints.api(name='my_api',version='v1', description='My API',
allowed_client_ids=ALLOWED_CLIENT_IDS)
class MyApi(remote.Service):
@endpoints.method(message_types.VoidMessage, DeviceListResponse,
name='user.device.list', path='user/device/list',
http_method='GET')
def user_device_list(self, request):
current_user = endpoints.get_current_user()
if current_user is None:
raise endpoints.UnauthorizedException('You must authenticate first.')
if current_user.user_id() is None:
raise endpoints.NotFoundException("Your user id was not found.")
return DeviceListResponse(devices=[]) #Hypothetically return devices
api_service = endpoints.api_server([MyApi], restricted=False)
Run Code Online (Sandbox Code Playgroud)
JS的起源包括:chrome-extensions:// chrome_app_id
var apiRoot = "https://my_app_id.appspot.com/_ah/api";
var …Run Code Online (Sandbox Code Playgroud) google-app-engine google-chrome-extension oauth-2.0 python-2.7 google-cloud-endpoints