简体   繁体   English

无法从客户端使用Google Cloud Endpoint插入

[英]Google Cloud Endpoint insert not working from client

I've been trying to set up a backend for my app using the Google Cloud Endpoints and everything seemed to be going well until I actually tried inserting entities into the datastore. 我一直在尝试使用Google Cloud Endpoints为我的应用设置一个后端,在我实际上尝试将实体插入数据存储之前,一切似乎都进行得很好。

I'm trying to insert the GenericBike objects to the datastore using the generated endpoints and while the code compiles and seems to runs successfully, nothing is ever actually inserted when I check the project webpage. 我正在尝试使用生成的端点将GenericBike对象插入数据存储区,并且虽然代码可以编译并且似乎可以成功运行,但是当我检查项目网页时实际上什么也没有插入。

Here is my code for actually inserting. 这是我实际插入的代码。

private class AddGenericBikeAsyncTask extends AsyncTask<GenericBike, Void, Void> {
    @Override
    protected Void doInBackground(GenericBike... params) {
        GenericBikeApi.Builder builder = new GenericBikeApi.Builder(AndroidHttp.newCompatibleTransport(),
                new AndroidJsonFactory(), null)
                .setRootUrl("https://banded-coder-125919.appspot.com/_ah/api/");
        GenericBikeApi service = builder.build();
        try {
            GenericBike bike = params[0];
            Log.e("Debug", "Inserting bike...");
            service.insert(bike);
            Log.e("Debug", "Done inserting bike.");
        } catch (IOException e) {e.printStackTrace(); }
        return null;
    }
}

And here is where I call it 这就是我所说的

if (mGenericBikes == null) { // we need to preload the database still
        for (int i=0; i<10; i++) {
            GenericBike bike = new GenericBike();
            bike.setId(new Long(i+1));
            new AddGenericBikeAsyncTask().execute(bike);
        }
    }

In case it helps, here is my GenericBike entitiy. 如果有帮助,这是我的GenericBike实体。

@Entity
public class GenericBike {

@Id Long mId;
boolean mAtStation;

public GenericBike() {
    mAtStation = true;
}

public Long getId() {
    return mId;
}

public void setId(Long id) {
    mId = id;
}

public boolean isAtStation() {
    return mAtStation;
}

public void setAtStation(boolean atStation) {
    mAtStation = atStation;
}

EDIT: Here is the generated endpoint code for the insert() method 编辑:这是为insert()方法生成的端点代码

/**
 * Inserts a new {@code GenericBike}.
 */
@ApiMethod(
        name = "insert",
        path = "genericBike",
        httpMethod = ApiMethod.HttpMethod.POST)
public GenericBike insert(GenericBike genericBike) {
    // Typically in a RESTful API a POST does not have a known ID (assuming the ID is used in the resource path).
    // You should validate that genericBike.mId has not been set. If the ID type is not supported by the
    // Objectify ID generator, e.g. long or String, then you should generate the unique ID yourself prior to saving.
    //
    // If your client provides the ID then you should probably use PUT instead.
    ofy().save().entity(genericBike).now();
    logger.info("Created GenericBike.");

    return ofy().load().entity(genericBike).now();
}

Looks like you are not launching the request from your client. 看起来您没有从客户端启动请求。 I believe you need to add .execute() to your client-lib object to actually kick off the request. 我相信您需要向客户端lib对象添加.execute()才能真正启动请求。

replace 更换

service.insert(bike);

with

service.insert(bike).execute();

Also, checking your App Engine logs is a good starting point to confirm that the request actually went through. 另外,检查您的App Engine日志也是确认请求确实通过的一个很好的起点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从客户端调用云端点库 - Calling cloud endpoint library from a client 我的后端API名称是什么? 它在哪里? 从Android Studio客户端调用Google Cloud端点后端API - What is my backend API name? Where is it? Calling Google Cloud endpoint backend API from Android Studio Client 生成Google Cloud终结点客户端库时获取MalformedJsonException - Getting MalformedJsonException while generating google cloud endpoint client library 在生成的Google Cloud Endpoint客户端库中包含子类 - Include sub-classes with generated Google Cloud Endpoint client library 生成云端点客户端库突然停止工作 - Generate cloud endpoint client library suddenly stopped working 我的Android客户端中的Google Cloud Endpoint身份验证:不允许受众,并且Oauth框架用户与oauth令牌用户不匹配 - Google Cloud Endpoint Authentication from my Android Client: Audience not Allowed and Oauth framework user didn't match oauth token user 将图像从Android客户端发送到AppEngine Cloud Endpoint - Send image from Android client to AppEngine Cloud Endpoint SSLHandshakeException云端点客户端库 - SSLHandshakeException cloud endpoint client lib 从Android调用Google Cloud端点时注入实体对象 - Injecting entity object while calling google cloud endpoint from android 无法从Android设备连接到Google Cloud端点 - Can't connect to google cloud endpoint from android device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM