【问题标题】:Calling Python API - Google App Engine调用 Python API - Google App Engine
【发布时间】:2014-01-14 00:48:32
【问题描述】:

在使用从我的 Python API for Google App Engine 生成的 .JAR 生成的 API 时,我有点困惑。

下面是一个方法和 AsyncTask 示例,用于在 Datastore 中创建和存储 Event 实体。

您通常会使用请求/响应消息将数据传递给实体吗?

我有一个 Event 类,它有一个 insert() 方法,但它不允许我将任何事件详细信息传递给它,因为它缺少像 Request/Response 类这样的 setter/getter

private void sendResultToServer(String eventDesc, String eventName,
        String eventTime) {
    ImhotepApiMessagesEventRequest newEvent = new ImhotepApiMessagesEventRequest();
    newEvent.setEventDesc(eventDesc);
    newEvent.setEventTitle(eventName);
    newEvent.setEventTime(eventTime);
    new SendResultToServerTask().execute(newEvent, null, null);
}

/**
 * Handles the request to the Event Endpoint, to save a event, without
 * blocking the UI.
 */
private class SendResultToServerTask extends
        AsyncTask<ImhotepApiMessagesEventRequest, Void, Void> {

    @Override
    protected Void doInBackground(
            ImhotepApiMessagesEventRequest... params) {
        // TODO Auto-generated method stub
        service.event();
        return null;
    }

【问题讨论】:

  • AppEngine Java 和 Python API 是分开的,无法移植 Python 代码。您似乎缺少一些概念。您的示例是 Java,因此您应该学习 Java Datastore APISamples。要回答您的问题,是的,您通常会在 doPost 事件处理程序中使用请求参数将数据传递给实体,并从 HTML 表单或 jQuery Ajax 调用提交帖子。

标签: java android python google-app-engine


【解决方案1】:

Java Using the Datastore 示例是使用留言簿 doPost 处理程序创建您自己的实体的良好起点。示例启动并运行后,您可以将其扩展到任务队列。

Using Push Queues in Java 中的第一个代码示例将命名参数添加到异步任务调用。根据Class TaskOptions,您可以链接 .param("name","value") 调用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-03
    • 1970-01-01
    • 2012-01-06
    相关资源
    最近更新 更多