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。我「定義了一個消息類,其中包含將在請求正文中傳遞的所有參數」,然後定義請求消息中使用的資源容器以包含該類。