【问题标题】:How can I use the WooCommerce REST API in an Android app? [duplicate]如何在 Android 应用中使用 WooCommerce REST API? [复制]
【发布时间】:2018-04-07 00:59:51
【问题描述】:

我已经生成了密钥和秘密,现在我不知道如何使用密钥和秘密,以便将数据从服务器获取到我的 Android 应用程序中。谁能告诉它的正确程序?我如何创建签名、nonce 和其他需要验证的东西?

【问题讨论】:

    标签: java php android


    【解决方案1】:

    使用 Volley 库是连接 API 的最简单方法。例如

        RequestQueue queue = Volley.newRequestQueue(this);
    
        String url = this.apiURl; //you could store it as config at raw
    
        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest
                (Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
    
                    @Override
                    public void onResponse(JSONObject response) {
    
                    // do nice things with your beautiful response 
    
    
                }, new Response.ErrorListener() {
    
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        // Handle error if any 
    
                    }
                });
    
        queue.add(jsonObjectRequest);
    

    Woocommerce 发送 json 响应,因此请使用 JsonObjectRequest,因此您无需再次将 String 转换为 Json。

    希望这会有所帮助!

    【讨论】:

    • 如何处理消费者密钥和消费者秘密?
    • 如果您检查了 woocommerce REST api 文档,您可以将这些键作为查询参数
    • 我怎样才能为 Auth 输入密钥和秘密?
    • ?consumer_key={}&amp;consumer_secret={}
    • 先生,我知道如何处理 http 请求,我已经尝试过了。我尝试将 consumer_key 和 cosumer_secret 作为参数发送......但我在这里遇到了一个错误 { "code": " woocommerce_rest_cannot_view", "message": "抱歉,您不能列出资源。", "data": { "status": 401 } }
    猜你喜欢
    • 2019-01-01
    • 1970-01-01
    • 2016-03-15
    • 1970-01-01
    • 2017-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-04
    相关资源
    最近更新 更多