为 Android 创建 drupal Web 服务

发布于 2024-12-06 02:47:42 字数 6659 浏览 1 评论 0原文

在设置 xmlrpc 时,我一直在特别努力地使用这个模块。
我正在使用 services 6.2 并在站点构建中启用 xmlrpc -> http://code.google.com/p/android-

然后我下载了这个库: xmlrpc/

为了保持简单,只是为了查看实现,没有涉及 API 密钥或会话密钥的安全功能,甚至匿名用户也可以访问 此链接

以下是我在 android 应用程序中使用的获取数据的代码:

XMLRPCClient client = new XMLRPCClient("http://mydomain.com/infra2/drupal-.19/services/xmlrpc");

try{
    Log.d("SUM",""+client.call("node.get",2));
}catch {
    e.printstacktrace();
}

我在这里获取节点 2 的完整数据,但它不是 XML 格式。此外,如果我使用以下代码:

Log.d("SUM",""+client.call("node.get",2,"user"));

特别获取创建节点 2 的用户。我收到错误,但在 drupal 框架中我可以使用这两个参数来过滤内容。

当我按照此链接中的建议使用 BasicNameValuePair 时:-

Android、Drupal & DrupalCloud 或 Android-xmlrpc 教程?

我得到的输出如下:

{uid=1, body=welcome , data=a:0:{}, type=panel, last_comment_name=, changed=1305012450, panels_node={did=1, pipeline=standard, nid=4, css_id=}, title=Welcome, created=1301322449, name=admin, revision_uid=1, taxonomy=[Ljava.lang.Object;@46378f28, tnid=0, vid=4, comment_count=0, files=[Ljava.lang.Object;@463776d8, status=1, nid=4, moderate=0, format=1, log=, picture=, sticky=0, promote=1, last_comment_timestamp=1301322449, teaser=welcome , revision_timestamp=1305012450, translate=0, language=, comment=0}

它是简单的 php 格式而不是 xml

我也尝试使用视图模块并使用视图数据源模块来获取输出在 xml 和 json 中,它运行良好。 但在这种情况下,我还必须设置对匿名用户的访问权限,并且由于我的 Android 应用程序将使用 api 调用来不安全的 url,因此主要问题将是安全性。 因此,如果有人可以为我提供使用 httpurlconnection 通过 android 登录 drupal 网站的方法,即使这样也能达到目的。

预先感谢

,当我使用 BasicNameValuePair 传递参数时,我在日志猫中得到了以下信息。

以下是我收到的错误:

09-21 13:09:59.793: WARN/System.err(18690): java.io.IOException: Cannot serialize nid=4
09-21 13:09:59.803: WARN/System.err(18690):     at org.xmlrpc.android.XMLRPCSerializer.serialize(XMLRPCSerializer.java:99)
09-21 13:09:59.803: WARN/System.err(18690):     at org.xmlrpc.android.XMLRPCCommon.serializeParams(XMLRPCCommon.java:36)
09-21 13:09:59.803: WARN/System.err(18690):     at org.xmlrpc.android.XMLRPCClient.methodCall(XMLRPCClient.java:250)
09-21 13:09:59.803: WARN/System.err(18690):     at org.xmlrpc.android.XMLRPCClient.callEx(XMLRPCClient.java:170)
09-21 13:09:59.803: WARN/System.err(18690):     at org.xmlrpc.android.XMLRPCClient.call(XMLRPCClient.java:281)
09-21 13:09:59.803: WARN/System.err(18690):     at com.drupal.DrupalActivity.onCreate(DrupalActivity.java:34)
09-21 13:09:59.803: WARN/System.err(18690):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
09-21 13:09:59.803: WARN/System.err(18690):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
09-21 13:09:59.803: WARN/System.err(18690):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803)
09-21 13:09:59.803: WARN/System.err(18690):     at android.app.ActivityThread.access$2300(ActivityThread.java:135)
09-21 13:09:59.803: WARN/System.err(18690):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
09-21 13:09:59.803: WARN/System.err(18690):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-21 13:09:59.803: WARN/System.err(18690):     at android.os.Looper.loop(Looper.java:144)
09-21 13:09:59.803: WARN/System.err(18690):     at android.app.ActivityThread.main(ActivityThread.java:4937)
09-21 13:09:59.803: WARN/System.err(18690):     at java.lang.reflect.Method.invokeNative(Native Method)
09-21 13:09:59.803: WARN/System.err(18690):     at java.lang.reflect.Method.invoke(Method.java:521)
09-21 13:09:59.803: WARN/System.err(18690):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-21 13:09:59.803: WARN/System.err(18690):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-21 13:09:59.803: WARN/System.err(18690):     at dalvik.system.NativeStart.main(Native Method)
09-21 13:09:59.803: WARN/System.err(18690): org.xmlrpc.android.XMLRPCException: java.io.IOException: Cannot serialize nid=4
09-21 13:09:59.803: WARN/System.err(18690):     at org.xmlrpc.android.XMLRPCClient.callEx(XMLRPCClient.java:237)
09-21 13:09:59.813: WARN/System.err(18690):     at org.xmlrpc.android.XMLRPCClient.call(XMLRPCClient.java:281)
09-21 13:09:59.813: WARN/System.err(18690):     at com.drupal.DrupalActivity.onCreate(DrupalActivity.java:34)
09-21 13:09:59.813: WARN/System.err(18690):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
09-21 13:09:59.813: WARN/System.err(18690):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
09-21 13:09:59.813: WARN/System.err(18690):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803)
09-21 13:09:59.813: WARN/System.err(18690):     at android.app.ActivityThread.access$2300(ActivityThread.java:135)
09-21 13:09:59.813: WARN/System.err(18690):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
09-21 13:09:59.813: WARN/System.err(18690):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-21 13:09:59.813: WARN/System.err(18690):     at android.os.Looper.loop(Looper.java:144)
09-21 13:09:59.813: WARN/System.err(18690):     at android.app.ActivityThread.main(ActivityThread.java:4937)
09-21 13:09:59.813: WARN/System.err(18690):     at java.lang.reflect.Method.invokeNative(Native Method)
09-21 13:09:59.813: WARN/System.err(18690):     at java.lang.reflect.Method.invoke(Method.java:521)
09-21 13:09:59.813: WARN/System.err(18690):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-21 13:09:59.813: WARN/System.err(18690):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-21 13:09:59.813: WARN/System.err(18690):     at dalvik.system.NativeStart.main(Native Method)
09-21 13:09:59.813: WARN/System.err(18690): Caused by: java.io.IOException: Cannot serialize nid=4
09-21 13:09:59.813: WARN/System.err(18690):     at org.xmlrpc.android.XMLRPCSerializer.serialize(XMLRPCSerializer.java:99)
09-21 13:09:59.813: WARN/System.err(18690):     at org.xmlrpc.android.XMLRPCCommon.serializeParams(XMLRPCCommon.java:36)
09-21 13:09:59.813: WARN/System.err(18690):     at org.xmlrpc.android.XMLRPCClient.methodCall(XMLRPCClient.java:250)
09-21 13:09:59.813: WARN/System.err(18690):     at org.xmlrpc.android.XMLRPCClient.callEx(XMLRPCClient.java:170)

提前致谢

I have been struggling particularly with this module in setting up xmlrpc.
I am using services 6.2 and enabled xmlrpc in site building -> module

Then I downloaded this library: http://code.google.com/p/android-xmlrpc/

For the purpose to keep it simple and just to see the implementation there is no security feature involved no API key or session key and even the anonymous user can visit this link.

The following is the code which I am using in my android application to get data:

XMLRPCClient client = new XMLRPCClient("http://mydomain.com/infra2/drupal-.19/services/xmlrpc");

try{
    Log.d("SUM",""+client.call("node.get",2));
}catch {
    e.printstacktrace();
}

I am getting the complete data of node 2 here but it is not in XML format. Moreover, if I use the following code:

Log.d("SUM",""+client.call("node.get",2,"user"));

to get particularly the user who created node 2. I am getting an error, but in drupal framework I can use both of the parameters to filter the content.

And when I use BasicNameValuePair like suggested in this link :-

Android, Drupal & DrupalCloud or Android-xmlrpc tutorial?

The output which I get is following :

{uid=1, body=welcome , data=a:0:{}, type=panel, last_comment_name=, changed=1305012450, panels_node={did=1, pipeline=standard, nid=4, css_id=}, title=Welcome, created=1301322449, name=admin, revision_uid=1, taxonomy=[Ljava.lang.Object;@46378f28, tnid=0, vid=4, comment_count=0, files=[Ljava.lang.Object;@463776d8, status=1, nid=4, moderate=0, format=1, log=, picture=, sticky=0, promote=1, last_comment_timestamp=1301322449, teaser=welcome , revision_timestamp=1305012450, translate=0, language=, comment=0}

which is in simple php format and not xml

I have also tried to get the same working with views module and using views data source module to get the output in xml and json and it is working well.
But in this case i have to set the access to anonymous user as well and since my android application will be using the api calls to unsecure urls the major issue will be security.
So if someone could provide me the method to loginto the drupal website via android using httpurlconnection even that would serve the purpose.

Thanks in advance

I get following in my log cat and when I use BasicNameValuePair to pass the parameters.

The following are the errors which i get:

09-21 13:09:59.793: WARN/System.err(18690): java.io.IOException: Cannot serialize nid=4
09-21 13:09:59.803: WARN/System.err(18690):     at org.xmlrpc.android.XMLRPCSerializer.serialize(XMLRPCSerializer.java:99)
09-21 13:09:59.803: WARN/System.err(18690):     at org.xmlrpc.android.XMLRPCCommon.serializeParams(XMLRPCCommon.java:36)
09-21 13:09:59.803: WARN/System.err(18690):     at org.xmlrpc.android.XMLRPCClient.methodCall(XMLRPCClient.java:250)
09-21 13:09:59.803: WARN/System.err(18690):     at org.xmlrpc.android.XMLRPCClient.callEx(XMLRPCClient.java:170)
09-21 13:09:59.803: WARN/System.err(18690):     at org.xmlrpc.android.XMLRPCClient.call(XMLRPCClient.java:281)
09-21 13:09:59.803: WARN/System.err(18690):     at com.drupal.DrupalActivity.onCreate(DrupalActivity.java:34)
09-21 13:09:59.803: WARN/System.err(18690):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
09-21 13:09:59.803: WARN/System.err(18690):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
09-21 13:09:59.803: WARN/System.err(18690):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803)
09-21 13:09:59.803: WARN/System.err(18690):     at android.app.ActivityThread.access$2300(ActivityThread.java:135)
09-21 13:09:59.803: WARN/System.err(18690):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
09-21 13:09:59.803: WARN/System.err(18690):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-21 13:09:59.803: WARN/System.err(18690):     at android.os.Looper.loop(Looper.java:144)
09-21 13:09:59.803: WARN/System.err(18690):     at android.app.ActivityThread.main(ActivityThread.java:4937)
09-21 13:09:59.803: WARN/System.err(18690):     at java.lang.reflect.Method.invokeNative(Native Method)
09-21 13:09:59.803: WARN/System.err(18690):     at java.lang.reflect.Method.invoke(Method.java:521)
09-21 13:09:59.803: WARN/System.err(18690):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-21 13:09:59.803: WARN/System.err(18690):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-21 13:09:59.803: WARN/System.err(18690):     at dalvik.system.NativeStart.main(Native Method)
09-21 13:09:59.803: WARN/System.err(18690): org.xmlrpc.android.XMLRPCException: java.io.IOException: Cannot serialize nid=4
09-21 13:09:59.803: WARN/System.err(18690):     at org.xmlrpc.android.XMLRPCClient.callEx(XMLRPCClient.java:237)
09-21 13:09:59.813: WARN/System.err(18690):     at org.xmlrpc.android.XMLRPCClient.call(XMLRPCClient.java:281)
09-21 13:09:59.813: WARN/System.err(18690):     at com.drupal.DrupalActivity.onCreate(DrupalActivity.java:34)
09-21 13:09:59.813: WARN/System.err(18690):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
09-21 13:09:59.813: WARN/System.err(18690):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
09-21 13:09:59.813: WARN/System.err(18690):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803)
09-21 13:09:59.813: WARN/System.err(18690):     at android.app.ActivityThread.access$2300(ActivityThread.java:135)
09-21 13:09:59.813: WARN/System.err(18690):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
09-21 13:09:59.813: WARN/System.err(18690):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-21 13:09:59.813: WARN/System.err(18690):     at android.os.Looper.loop(Looper.java:144)
09-21 13:09:59.813: WARN/System.err(18690):     at android.app.ActivityThread.main(ActivityThread.java:4937)
09-21 13:09:59.813: WARN/System.err(18690):     at java.lang.reflect.Method.invokeNative(Native Method)
09-21 13:09:59.813: WARN/System.err(18690):     at java.lang.reflect.Method.invoke(Method.java:521)
09-21 13:09:59.813: WARN/System.err(18690):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-21 13:09:59.813: WARN/System.err(18690):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-21 13:09:59.813: WARN/System.err(18690):     at dalvik.system.NativeStart.main(Native Method)
09-21 13:09:59.813: WARN/System.err(18690): Caused by: java.io.IOException: Cannot serialize nid=4
09-21 13:09:59.813: WARN/System.err(18690):     at org.xmlrpc.android.XMLRPCSerializer.serialize(XMLRPCSerializer.java:99)
09-21 13:09:59.813: WARN/System.err(18690):     at org.xmlrpc.android.XMLRPCCommon.serializeParams(XMLRPCCommon.java:36)
09-21 13:09:59.813: WARN/System.err(18690):     at org.xmlrpc.android.XMLRPCClient.methodCall(XMLRPCClient.java:250)
09-21 13:09:59.813: WARN/System.err(18690):     at org.xmlrpc.android.XMLRPCClient.callEx(XMLRPCClient.java:170)

Thanks in advance

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

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

发布评论

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

评论(1

萌吟 2024-12-13 02:47:42

尝试创建一个 for 循环,我认为在此之前您必须获取大小并存储它,然后将其作为 for 循环中的计数。

coutnt=0;
count=getname().getsize(){of the item}

for(;count;){
   put the value inside the loop.
}

Try creating a for loop , I think before that you have to get the size and store it and then make it as a count in the for loop.

coutnt=0;
count=getname().getsize(){of the item}

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