drupal 和 appcelerator titan 之间的 node.save 服务存在问题

发布于 2024-10-15 02:15:30 字数 2396 浏览 6 评论 0原文

我正在使用 Appcelerator Titanium 编写我的第一个应用程序,但我遇到了一个似乎可以摆脱的障碍。我使用过的所有其他服务都是通过 JSON 服务器(node.get、view.get、system.connect)工作的,但我一生都无法获得 node.save 的工作解决方案。我尝试过寻找与我同一条船上的人,但找不到任何东西,但我也无法在任何地方找到可行的解决方案。

我使用以下博客文章作为起点: http://civicactions.com/blog/2010/may/02/tutorial_code_developing_apps_iphoneipadandroid_using_drupal_base_system

我尝试过 JSON 和 XMLRPC,但 JSON 没有任何响应,并且 XMLRPC 拒绝访问。如果我通过 drupal admin 将 JSON 插入服务页面,它将创建一个节点(不是 CCK 节点,但它与故事一起使用),但浏览应用程序时我什么也得不到。

以下是我尝试使用 XMLRPC 的输出:

节点对象 -

[INFO] {
sessid = b03429453c85d4bf3d600dff6511f70f;
title = "This is a new node.";
type = story;
}



[INFO] xmlrpc: begin
[INFO] xmlrpc: url: http://mysite/services/xmlrpc
[INFO] xmlrpc: method: node.save
[INFO] xmlrpc: p: story
[INFO] xmlrpc: p: This is a new node.
[INFO] xmlrpc: p: b03429453c85d4bf3d600dff6511f70f

正在发送 XML -

[INFO] xmlrpc: xml: <methodCall><methodName>node.save</methodName><params><param><string>story</string></param><param><string>This is a new node.</string></param><param><string>b03429453c85d4bf3d600dff6511f70f</string></param></params></methodCall>
[INFO] xmlrpc: end

响应 -

[INFO] Received: <?xml version="1.0"?>
<methodResponse>
<fault>
<value>
<struct>
<member>
<name>faultCode</name>
<value><int>401</int></value>
</member>
<member>
<name>faultString</name>
<value><string>Access denied</string></value>
</member>
</struct>
</value>
</fault>
</methodResponse>

这是我使用 JSON 得到的结果:

[INFO] {"method":"node.save","type":"story","title":"This is a new node.","sessid":"b03429453c85d4bf3d600dff6511f70f"}
[INFO] node.save response: undefined
[WARN] Exception in event callback. {
line = 90;
message = "Unable to parse JSON string";
name = SyntaxError;
sourceId = 204738256;
sourceURL = "file://localhost/Users/justin/Sites/Apps/appname/Resources/add.js";
}

我没有拒绝访问,但它没有将响应发送回应用程序。

有其他人遇到过这个问题吗?如果是的话,您能找到解决办法吗?

I am writing my first app using Appcelerator Titanium and I've hit a snag that I can seem to shake. Every other service I have used is working through the JSON server (node.get, view.get,system.connect) but I cannot for the life of me get a working solution of node.save. I've tried searching for people in my same boat and can't really find anything but I also cannot find a working solution anywhere.

I used the following blog post as a starting point:
http://civicactions.com/blog/2010/may/02/tutorial_code_developing_apps_iphoneipadandroid_using_drupal_base_system

I've tried both JSON and XMLRPC but I get no response with JSON and Access Denied with XMLRPC. If I plug my JSON into the services page through drupal admin it will create a node (not a CCK node but it worked with story) but going through the app I get nothing.

The following is my output trying with XMLRPC:

Node object -

[INFO] {
sessid = b03429453c85d4bf3d600dff6511f70f;
title = "This is a new node.";
type = story;
}



[INFO] xmlrpc: begin
[INFO] xmlrpc: url: http://mysite/services/xmlrpc
[INFO] xmlrpc: method: node.save
[INFO] xmlrpc: p: story
[INFO] xmlrpc: p: This is a new node.
[INFO] xmlrpc: p: b03429453c85d4bf3d600dff6511f70f

XML being sent -

[INFO] xmlrpc: xml: <methodCall><methodName>node.save</methodName><params><param><string>story</string></param><param><string>This is a new node.</string></param><param><string>b03429453c85d4bf3d600dff6511f70f</string></param></params></methodCall>
[INFO] xmlrpc: end

Response -

[INFO] Received: <?xml version="1.0"?>
<methodResponse>
<fault>
<value>
<struct>
<member>
<name>faultCode</name>
<value><int>401</int></value>
</member>
<member>
<name>faultString</name>
<value><string>Access denied</string></value>
</member>
</struct>
</value>
</fault>
</methodResponse>

Here is what I am getting with JSON:

[INFO] {"method":"node.save","type":"story","title":"This is a new node.","sessid":"b03429453c85d4bf3d600dff6511f70f"}
[INFO] node.save response: undefined
[WARN] Exception in event callback. {
line = 90;
message = "Unable to parse JSON string";
name = SyntaxError;
sourceId = 204738256;
sourceURL = "file://localhost/Users/justin/Sites/Apps/appname/Resources/add.js";
}

I'm not getting access denied but it isn't sending a response back to the app.

Has anyone else ran into this issue and if so have you been able to find a fix for it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

独木成林 2024-10-22 02:15:30

目前 Sumit 博客中修改后的 JSON 服务器存在一些问题。该补丁是为了与以前版本的 services 2 一起使用而制作的。两天前我正在处理同样的问题。我非常疯狂地工作,不幸的是我不再记得一切是如何展开的。问题之一是过时的 json 服务器模块导致服务崩溃。同样,我不再记得细节,但这是我找到的解决方案。它仅适用于 php 5.2 +,因为它使用 json_encode 和 json_decode。首先拉取最新稳定版本的 JSON Server。
要点是 json_decode 应该返回关联数组而不是 php 对象,因为这是 Drupal 所期望的。所以你调用 json_decode($json_string,TRUE),使用布尔开关使 json_decode 返回 assoc 数组。下面是一个快速但非常肮脏的解决方案:

     function json_server_server() {
    $_POST = json_decode($_POST['data'],true);
    $_POST = (array)$_POST;
    if (!isset($_POST)) {
      return drupal_to_js(array('error' => TRUE, 'data' => "JSON server accepts POST     requests only."));
    }

  $methods = services_get_all();
  services_strip_hashes($methods);
  $request = $_POST['method'];
  $args = array();


  foreach ($methods as $method) {
    if ($method['method'] == $request) {
      unset($_POST['q']);
      unset($_POST['method']);
      $args = array();
      foreach($method['args'] as $arg) {
        if(isset($_POST[$arg['name']])) {
          $args[] = $_POST[$arg['name']];
        }
        elseif($arg['optional'] == 0) {
          return drupal_to_js(array("error" => TRUE, "data" => "Argument ". $arg['name']   ." not recieved"));
        }
        else {
          $args[$arg['name']] = NULL;
        }
      }
      $result = services_method_call($method['method'], $args);

      if (is_array($result) && $result['error'] === TRUE) return  drupal_to_js(array('error' => TRUE, 'data' => $result['message']));

      return(json_encode($result)); //json encode the result, not including the error
    }
  }

  return drupal_to_js(array('error' => TRUE, 'data' => "Invalid  method $request"));
}

There are a few problems with the modified JSON server from Sumit's blog at this moment. The patch was made to work with a previous version of services 2. Two days ago I was dealing with the same issue. I was working quite frantically and unfortunaly don't remember anymore how everything unfolded. One of the issues is that the outdated json server module makes services crash. Again, I don't remember the details anymore, but here is the solution I found. It's php 5.2 + only , as it uses json_encode and json_decode. First pull the latest stable version of JSON Server.
Main point is that json_decode should return associative arrays instead of php objects, as that is what Drupal is expecting. So you call json_decode($json_string,TRUE), using the boolean switch makes json_decode return assoc arrays. So below a quick and very dirty solution:

     function json_server_server() {
    $_POST = json_decode($_POST['data'],true);
    $_POST = (array)$_POST;
    if (!isset($_POST)) {
      return drupal_to_js(array('error' => TRUE, 'data' => "JSON server accepts POST     requests only."));
    }

  $methods = services_get_all();
  services_strip_hashes($methods);
  $request = $_POST['method'];
  $args = array();


  foreach ($methods as $method) {
    if ($method['method'] == $request) {
      unset($_POST['q']);
      unset($_POST['method']);
      $args = array();
      foreach($method['args'] as $arg) {
        if(isset($_POST[$arg['name']])) {
          $args[] = $_POST[$arg['name']];
        }
        elseif($arg['optional'] == 0) {
          return drupal_to_js(array("error" => TRUE, "data" => "Argument ". $arg['name']   ." not recieved"));
        }
        else {
          $args[$arg['name']] = NULL;
        }
      }
      $result = services_method_call($method['method'], $args);

      if (is_array($result) && $result['error'] === TRUE) return  drupal_to_js(array('error' => TRUE, 'data' => $result['message']));

      return(json_encode($result)); //json encode the result, not including the error
    }
  }

  return drupal_to_js(array('error' => TRUE, 'data' => "Invalid  method $request"));
}
内心旳酸楚 2024-10-22 02:15:30

尝试将参数放在引号之间;像“节点.保存”;它对我有用。

Try wrapping your parameters between quotes; like "node.save"; it worked for me.

巴黎夜雨 2024-10-22 02:15:30

node.getview.getsystem.connect 使用与 node.save 不同的权限。它们很可能都被授权给匿名用户,而 node.save 则没有。既然您提到了system.connect,我猜您已经尝试在调用node.save之前启动经过身份验证的会话。您确定通话之间的会话得到正确维护吗?

此外,

Exception in event callback. {
  line = 90;
  message = "Unable to parse JSON string";
  name = SyntaxError;
  sourceId = 204738256;
  sourceURL = "file://localhost/Users/justin/Sites/Apps/appname/Resources/add.js";
}

这看起来更像是处理服务器响应的应用程序代码中的异常,而不是服务器端的错误。这很可能是由于服务器在拒绝访问时返回 HTTP 403 错误而没有 JSON 正文引起的。

node.get, view.get and system.connect use different permissions than node.save. Its likely that they are all authorized for the anonymous user while node.save isn't. Since you mention system.connect, I guess you already try to start an authenticated session before calling node.save. Are you sure the session is properly maintained between calls?

Also,

Exception in event callback. {
  line = 90;
  message = "Unable to parse JSON string";
  name = SyntaxError;
  sourceId = 204738256;
  sourceURL = "file://localhost/Users/justin/Sites/Apps/appname/Resources/add.js";
}

This looks more like an exception in the application code handling the server response than an error server-side. It is likely that this is caused by the server returning an HTTP 403 error without a JSON body on access denied.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文