android - GoogleJsonResponseException : 404 Not Found using google apps endpoint engine backend

标签 android google-app-engine google-cloud-endpoints

我遵循了下面的教程。

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

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

之后的异常
Note result = endpoint.insertNote(note).execute();

被调用。

com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found

我的代码如下。

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;
        }
    }
}

最佳答案

此问题的另一个可能原因是没有在 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>

...

</appengine-web-app>

关于android - GoogleJsonResponseException : 404 Not Found using google apps endpoint engine backend,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15563913/

相关文章:

java - 在java中将文本文件转换为字符串

android - 如何在 Android 应用程序及其库之间共享 gradle 依赖项?

java - HttpURLConnection 和获取 ASPX 页面

google-cloud-endpoints - 如何从 Chrome 应用程序中使用 Google Cloud Endpoints?

java - 暂停可运行的线程并等待用户输入

google-app-engine - App Engine Multi-Tenancy SSL 和计费

google-app-engine - Google App Engine - 如何记住用户登录?

java - 谷歌应用引擎中的排序结果

java - 在 App Engine 数据存储中设置文本数据类型的编码

node.js - Firebase 的云功能 : how to issue a request to my Cloud Endpoint