Dart无法访问云端点API

时间:2013-03-05 16:50:15

标签: dart google-cloud-endpoints

令人沮丧的是,我被困在这里一个星期而且没有任何线索如何解决它; (

受到Gerwin Sturm的出色工作(https://github.com/Scarygami/gdg-endpoint-demo)的启发,我喜欢构建java后端。

但不幸的是,每当我尝试调用端点API时,都会出现NoSuchMethodError错误。

Exception: NoSuchMethodError : method not found: '_client@0x296594a'
Receiver: Instance of 'Dbentryendpoint'
Arguments: []
Stack Trace: #0      Object.noSuchMethod (dart:core-patch:1737:25)
#1      Dbentryendpoint.listDBEntry (http://127.0.0.1:3030/C:/Users/VincentZhou/dart/dart_dbentryendpoint_v1_api_client/packages/google_dbentryendpoint_v1_api/src/browser/dbentryendpoint.dart:162:16)
#2      main.fetch (http://127.0.0.1:3030/C:/Users/VincentZhou/dart/dart_dbentryendpoint_v1_api_client/demo.dart:24:20)
#3      main (http://127.0.0.1:3030/C:/Users/VincentZhou/dart/dart_dbentryendpoint_v1_api_client/demo.dart:64:8)

Exception: NoSuchMethodError : method not found: '_client@0x296594a'
Receiver: Instance of 'Dbentryendpoint'
Arguments: []
Stack Trace: #0      Object.noSuchMethod (dart:core-patch:1737:25)
#1      Dbentryendpoint.insertDBEntry (http://127.0.0.1:3030/C:/Users/VincentZhou/dart/dart_dbentryendpoint_v1_api_client/packages/google_dbentryendpoint_v1_api/src/browser/dbentryendpoint.dart:124:16)
#2      main.<anonymous closure>.<anonymous closure>.<anonymous closure>.<anonymous closure> (http://127.0.0.1:3030/C:/Users/VincentZhou/dart/dart_dbentryendpoint_v1_api_client/demo.dart:56:28)

demo.dart的源代码几乎与原始代码(https://github.com/Scarygami/gdg-endpoint-demo)相同,我只更改了cloudendpint API和Web客户端ID。

import "dart:html";
import 'packages/google_dbentryendpoint_v1_api/dbentryendpoint_v1_api_browser.dart' as gdglib;
import 'packages/google_plus_v1_api/plus_v1_api_browser.dart' as pluslib;
import 'packages/google_oauth2_client/google_oauth2_browser.dart';

final CLIENT_ID = "878766780041.apps.googleusercontent.com";
final SCOPES = ["https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/plus.me"];

void main() {
  var auth = new GoogleOAuth2(CLIENT_ID, SCOPES);
  var gdg = new gdglib.Dbentryendpoint(auth);
  var plus = new pluslib.Plus(auth);
  var container = query("#entries");
  var loginButton = query("#login");
  var sendButton = query("#send");
  InputElement textInput = query("#text");
  var authorSpan = query("#author");
  pluslib.Person me;


  void fetch() {
    //gdg.makeAuthRequests = false;
    gdg.makeAuthRequests = true;
    gdg.listDBEntry(limit:10).then((l) {
      container.text = "";
      if (l.items != null) {
        l.items.forEach((e) {
          var p = new ParagraphElement();
          var date = e.date.replaceAll("T", " ");
          p.text = "$date - ${e.author}: ${e.text}";
          container.append(p);
        });
      }
    });
  }

  loginButton.onClick.listen((Event e) {
    auth.login().then((token) {
      loginButton.style.display = "none";
      plus.makeAuthRequests = true;
      plus.people.get("me").then((p) {
        me = p;
        authorSpan.text = "${me.displayName}:";
        authorSpan.style.display = "inline-block";
        textInput.style.display = "inline-block";
        sendButton.style.display = "inline-block";

        sendButton.onClick.listen((Event e) {
          var text = textInput.value;
          textInput.value = "";
          var entry = new gdglib.DBEntry.fromJson({
            "author": me.displayName,
            "text": text
          });
          gdg.makeAuthRequests = true;
          gdg.insertDBEntry(entry).then((entry) {
            fetch();
          });
        });
      });
    });
  });

在Google App Engine方面,我自动生成云端点类,然后添加客户端ID相关信息:

@Api(name = "dbentryendpoint",
        clientIds={Ids.WEB_CLIENT_ID,com.google.api.server.spi.Constant.API_EXPLORER_CLIENT_ID},
        scopes={"https://www.googleapis.com/auth/userinfo.email"}
)
public class DBEntryEndpoint {
.....

感谢任何帮助!

2 个答案:

答案 0 :(得分:0)

包导入看起来不正确,试试这个。

import 'packages:google_dbentryendpoint_v1_api/dbentryendpoint_v1_api_browser.dart' as gdglib;
import 'packages:google_plus_v1_api/plus_v1_api_browser.dart' as pluslib;
import 'packages:google_oauth2_client/google_oauth2_browser.dart';

答案 1 :(得分:0)

我想我找出了解决问题的方法,但我不知道为什么:

  1. GPE的“生成云端点”不会生成路径, 例如,它生成方法listEntities,而不是entities.list
  2. 路径是生成资源所必需的     _ah / API /发现/ V1 / API的/ dbentryendpoint / V1 /休息;没有路径,只有模式和方法,而不是模式和资源
  3. 没有资源,Dart客户端生成器只导出为空     resouces.dart在/ commom文件夹下。而方法将在里面     entityEndpoints.dart,无法正确识别     _client(),在/ common。
  4. 下的client.dart中定义

    所以demo.dart找不到方法。

    问题:为什么路径是必要的?因为GPE不会自动生成路径,我们是否有办法生成正确的dart客户端文件而无需在谷歌应用引擎文件中手动添加路径?感谢。