首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android-Magento-如何使用XML-RPC获取Android中多个产品的详细信息

Android-Magento-如何使用XML-RPC获取Android中多个产品的详细信息
EN

Stack Overflow用户
提问于 2012-08-09 07:41:32
回答 3查看 2.7K关注 0票数 10

如何使用XMLRPC从Magento.I获取Single Call中的多个产品的详细信息,我能够使用XMLRPC函数获得使用该函数的产品列表。

现在,我有了所有产品的SKU id,我可以使用函数获取每个产品的媒体细节

如果假设我有10个产品,我必须调用10次product_media.list方法对每个产品,这需要很长的时间。

那么,如何在安卓系统中调用MagentomultiCall函数呢?php中许多用于调用multiCall函数的教程都发布了,但我无法在Android中模仿它。

因此,如果您有类似的代码片段,请帮助我理解multiCall函数(for Android),这样我就可以进一步使用它。

谢谢。

Josua Marcel C 的答案中的PHP代码示例

代码语言:javascript
复制
$session = $client->call('login', array('apiUser', 'apiKey'));
$client->call('call', array($session,'somestuff.method', array('arg1', 'arg2', 'arg3')));  
$client->call('call', array($session, 'somestuff.method', 'arg1'));   
$client->call('call', array($session, 'somestuff.method'));

$client->call('multiCall', 
               array($session,
                  array(
                      array('somestuff.method', 'arg1'),
                      array('somestuff.method', array('arg1', 'arg2')),
                      array('somestuff.method')
                   )
              )
            );  

我想模仿上面在Android中调用Magento的multiCall()函数的php代码。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-08-29 10:52:53

在进行了长时间的研究之后,我得到了半程解决方案,称之为,没有任何Error,但我仍然不知道如何在一个变量中得到Server的响应,并使用它。

AnyOne有knowledge关于这方面的知识,可以编辑应答,我会感谢他的。

我使用的Code是:

代码语言:javascript
复制
Object[] skuid=new Object[product_list.size()];
Object calling[]=new Object[product_list.size()];

for(int m=0;m<product_list.size();m++)
{
    skuid[m]=new Object[]{product_list.get(m).getp_Sku()};
    calling[m]=new Object[]{"catalog_product_attribute_media.list",skuid[m]};   
}

try 
{
  client.callEx("multiCall",new Object[]{Utils.sessionId,calling});
}
catch (XMLRPCException e) 
{
    e.printStackTrace();
}  

AcknowledgeMents:

我一直在研究 艾恩发布的答案。

票数 3
EN

Stack Overflow用户

发布于 2012-08-19 04:01:43

答案

,因为android是基于java应用程序的,所以可以使用这个.

代码语言:javascript
复制
package org.apache.xmlrpc;

import java.util.Hashtable;
import java.util.Vector;

public class MultiCall
implements ContextXmlRpcHandler
{
    public Object execute(String method, Vector params, XmlRpcContext context)
            throws Exception
    {
        if ("multicall".equals(method))
        {
            return multicall(params, context);
        }

        throw new NoSuchMethodException("No method '" + method + "' in " + this.getClass().getName());
    }

    public Vector multicall(Vector requests, XmlRpcContext context)
    {
        // The array of calls is passed as a single parameter of type array.
        requests=(Vector)requests.elementAt(0);
        Vector response = new Vector();
        XmlRpcServerRequest request;
        for (int i = 0; i < requests.size(); i++)
        {
            try
            {
                Hashtable call = (Hashtable) requests.elementAt(i);
                request = new XmlRpcRequest((String) call.get("methodName"),
                                            (Vector) call.get("params"));
                Object handler = context.getHandlerMapping().getHandler(request.getMethodName());
                Vector v = new Vector();
                v.addElement(XmlRpcWorker.invokeHandler(handler, request, context));
                response.addElement(v);
            }
            catch (Exception x)
            {
                String message = x.toString();
                int code = (x instanceof XmlRpcException ?
                            ((XmlRpcException) x).code : 0);
                Hashtable h = new Hashtable();
                h.put("faultString", message);
                h.put("faultCode", new Integer(code));
                response.addElement(h);
            }
        }
        return response;
    }
}

来源

既然Magento支持SOAP,为什么不使用SOAP v1?因为肥皂很强大。试着到这里来,XML和SOAP有什么区别?

Android运行时中不包含Soap消息的解析,因此并不是很简单。您应该使用外部库。我在用ksoap2。

如果您在StackOverflow上搜索,您将看到许多关于如何使用它的示例。例如,这里

更多参考资料:链接1 链接2

带PHP的MultiCall

代码语言:javascript
复制
$client = new Zend_XmlRpc_Client('http://magentohost/api/xmlrpc/');

// If somestuff requires api authentification,
// we should get session token
$session = $client->call('login', array('apiUser', 'apiKey'));

$client->call('call', array($session, 'somestuff.method', array('arg1', 'arg2', 'arg3')));
$client->call('call', array($session, 'somestuff.method', 'arg1'));
$client->call('call', array($session, 'somestuff.method'));
$client->call('multiCall', array($session,
     array(
        array('somestuff.method', 'arg1'),
        array('somestuff.method', array('arg1', 'arg2')),
        array('somestuff.method')
     )
));

// If you don't need the session anymore
$client->call('endSession', array($session));
票数 2
EN

Stack Overflow用户

发布于 2012-08-20 08:31:22

首先,无论以什么方式登录,都可以调用catalog_product.list。确保sessionclientproduct_ids有正确的值。如果您不需要登录这些操作,设置session = null (如果不起作用,尝试根本不传递会话:)。然后:

代码语言:javascript
复制
Object[][] calls = new Object[product_ids.length];
for (int i = 0; i < product_ids.length; i++) {
    calls[i] = new Object[] { "product_media.list", product_ids[i] };
}
product_media_ids = client.call("multiCall", new Object[] { session, calls });

然后,product_media_ids应该是一个产品映像数组--也就是说,product_media_ids的每个元素都将是来自product_media.list的返回值。

恐怕密码是未经测试的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11878817

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档