0

我有一个Google App Engine应用程序。后端使用Python,前端使用JavaScript。该应用程序按预期在本地运行,并且API Explorer在部署时按预期工作。Google Cloud Endpoints:端点请求参数(资源容器)部署时为空

但是,API在部署时无法像预期那样工作。问题在于,来自请求的参数(“资源容器”)的云端点方法会收到“空”请求 - 从JavaScript前端给予请求的参数消失。

下面是一个例子。

的JavaScript API调用:

var id_resource = {'resource': {'user_google_id': "-1"}}; 

gapi.client.word_match.get_user_from_google_id(id_resource).execute(function(resp) { 

    console.log(resp); // THE API CALL 'LOSES' THE 'user_google_id' WHEN DEPLOYED: THIS LOGS AN ERROR ("Object {code: 404, data: Array[1], message: "No user with the id "None" exists.", error: Object}") WHEN DEPLOYED, BUT LOGS THE CORRECT USER INFO LOCALLY 
    if (!resp.code) { 

     self.user(new User(resp)); 
    } 
}); 

云端点:

REQUEST_BY_GOOGLE_ID = endpoints.ResourceContainer(user_google_id=messages.StringField(1),) 

@endpoints.api(name='word_match', version='v1', allowed_client_ids=['the id'], 
    auth_level=endpoints.AUTH_LEVEL.OPTIONAL_CONTINUE) 
class WordMatchApi(remote.Service): 
    """Game API 
    """ 
    @endpoints.method(request_message=REQUEST_BY_GOOGLE_ID, 
         response_message=UserForm, 
         path='getuser', 
         name='get_user_from_google_id', 
         http_method='POST') 
    def get_user_from_google_id(self, request): 
     """Get a user by the user's google account ID 
     """ 

     logging.info(request) // THIS IS THE ISSUE: LOGS "<CombinedContainer> user_google_id: u'-1'>" locally, but just "<CombinedContainer>" when deployed. 
     logging.info(request.user_google_id) 

     user = User.query(User.google_id == request.user_google_id).get() 

     if not user: 
      message = 'No user with the id "%s" exists.' % request.user_google_id 
      raise endpoints.NotFoundException(message) 

     return user.to_form() 

部署在哪里什么时候user_google_id去请求?为什么Python认为那里什么都没有?

回答

0

我明白了。主要修复基于this documentation。我“定义了一个消息类,其中包含将在请求正文中传递的所有参数”,然后定义请求消息中使用的资源容器以包含该类。