woocommerce rest api OAuth authentication in android

后端 未结 2 1892
你的背包
你的背包 2021-01-02 20:01

what is the sample code for OAuth 1.0a(one leg) authentication in android? is there a library for it? . I use eclipse and i\'m new in android. can anyone clarify the path fo

2条回答
  •  没有蜡笔的小新
    2021-01-02 20:17

    new Thread() {
                @Override
                public void run() {
                        String RESOURCE_URL = "http://www.woocommerce.com/wp-json/wc/v1/api/";
                        String SCOPE = "*"; //all permissions
                        Response response;
                        OAuthRequest request;
                        String responsebody = "";
                        OAuthService service = new ServiceBuilder().provider(OneLeggedApi10.class)
                                .apiKey("yourConsumerKey")
                                .apiSecret("yourConsumerSecret")
                                .signatureType(SignatureType.QueryString)
                                .debug()
                                /*.scope(SCOPE).*/
                                .build();
    
                        request = new OAuthRequest(Verb.GET, RESOURCE_URL);
                        service.signRequest(new Token("", ""), request);
    
                        // Now let's go and ask for a protected resource!
                        Log.d("scribe","Now we're going to access a protected resource...");
    
                    try {
                        response = request.send();
                        if (response.isSuccessful()) {
                            responsebody = response.getBody();
                            Log.v("response", responsebody);
                        }
    
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }.start();
    

    This code is updated from above, the above code is working getting JSON from wordpress Woocommerce API. But if you wondering how to use Thread this is the answer. And I add Log.v for see the json response.

提交回复
热议问题