GoogleJsonResponseException:404 Not Found使用谷歌应用程序端点引擎后端

Jak*_*ake 6 google-app-engine android google-cloud-endpoints

我按照下面的教程.

https://developers.google.com/eclipse/docs/running_and_debugging_2_0

它基本上为我现有的应用程序添加了GAE后端.然后,我尝试下面的示例,在本地开发服务器上运行它,然后我得到下面发生的异常

Note result = endpoint.insertNote(note).execute();
Run Code Online (Sandbox Code Playgroud)

叫做.

com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found
Run Code Online (Sandbox Code Playgroud)

我的代码如下.

package com.cloudnotes;

import java.io.IOException;
import java.util.Date;

import android.os.AsyncTask;
import android.content.Context;
import com.cloudnotes.noteendpoint.Noteendpoint;
import com.cloudnotes.noteendpoint.model.Note;
import com.google.api.client.extensions.android.http.AndroidHttp;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.json.jackson.JacksonFactory;


import android.os.Bundle;
import android.app.Activity;

import android.view.Menu;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

      new EndpointsTask().execute(getApplicationContext());
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    public class EndpointsTask extends AsyncTask<Context, Integer, Long> {
        protected Long doInBackground(Context... contexts) {

          Noteendpoint.Builder endpointBuilder = new Noteendpoint.Builder(
              AndroidHttp.newCompatibleTransport(),
              new JacksonFactory(),
              new HttpRequestInitializer() {
              public void initialize(HttpRequest httpRequest) { }
              });
      Noteendpoint endpoint = CloudEndpointUtils.updateBuilder(
      endpointBuilder).build();
      try {
          Note note = new Note().setDescription("Note Description");
          String noteID = new Date().toString();
          note.setId(noteID);

          note.setEmailAddress("E-Mail Address");      
          Note result = endpoint.insertNote(note).execute();
      } catch (IOException e) {
        e.printStackTrace();
      }
          return (long) 0;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

kg.*_*kg. 5

导致此问题的另一个可能原因是未在appengine-web.xml中设置正确的applicationId:

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
  <application>APPLICATION_ID_HERE</application>
Run Code Online (Sandbox Code Playgroud)

...

</appengine-web-app>
Run Code Online (Sandbox Code Playgroud)


ama*_*its 5

如果使用null参数调用方法并且该方法不接受空参数,则404的另一个可能原因.

我有一个类似的问题,一个方法有4个字符串参数,我为其中一个发送了null,我得到的只是一个愚蠢的404.

开发(本地)服务器上404的另一个可能原因是你有一个带有一些奇怪字符的参数(比如一个url),如果开发(本地)服务器在app引擎上正常工作,它就无法正确处理事件服务器.可能的解决方案:使用简单的java对象而不是多个params.


hbi*_*uni 0

发生这种情况是因为您的部署后端未完全部署。只需重新部署您的后端并确保您收到部署成功的消息。您可以在首页标题上查看详细的部署过程。另外,您可以通过访问 url 进行测试:

https://developers.google.com/apis-explorer/?base=https://[YOUR_PROJECT_ID].appspot.com/_ah/api#p/
Run Code Online (Sandbox Code Playgroud)