2

I am new to Android and I am using JAVA and Android studio. I have to use the WooCommerce API to get the list of all orders:

wp-json/wc/v2/orders

Is this possible using the volley library and if yes, how can I call this and get the response (I have my client_id and client_secret)?

Here is my activity page:

public class YourOrders extends AppCompatActivity {
private TextView textViewback;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_your_orders);
    getSupportActionBar().hide();
    textViewback = (TextView) findViewById(R.id.textViewback);
    textViewback.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            finish();
        }
    });
}}
scopchanov
  • 7,966
  • 10
  • 40
  • 68
Brajesh
  • 41
  • 8

1 Answers1

1
String url = "https://www.example.com/wp-json/wc/v2/orders?consumer_key=123&consumer_secret=abc";

JsonObjectRequest jsonObjectRequest = new JsonObjectRequest
    (Request.Method.GET, url, null, new Response.Listener<JSONObject>() {

@Override
public void onResponse(JSONObject response) {
    textViewback.setText("Response: " + response.toString()); 
    }
},  

   new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
    // TODO: Handle error

}
});
// Access the RequestQueue through your singleton class.
MySingleton.getInstance(this).addToRequestQueue(jsonObjectRequest);
Kayson
  • 26
  • 1
  • 4
  • While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. – TheTanic Sep 13 '18 at 14:42
  • Thankypou ,it solved the problem as consumer_key and consumer_secret served as for the purpose for authentication . – Brajesh Oct 01 '18 at 06:03