The most important thing that we are going to share with you guys today, that is how to verify woocommerce in the android app. Let’s check out the steps for Woocommerce authentication in the Android app.
Verify Woocommerce in Android App
WooCommerce Settings
- Login to a WordPress site, and the menu will be displayed at the left side of the page from there select WooCommerce and select Settings menu under WooCommerce menu.
- Setting options will appear in the content window select the API tab. Select settings under the API section. Check the Enable REST API checkbox to allow rest API access.
- Select the Keys/Apps tab under the API section to add a key for the user and click the Add key button, add a description for the key and select user for which key will be generated. Always select Permission as Read/Write to have access to REST API for GET and POST methods.
- Add key by providing details. And click on the Generate API Key button Consumer key and consumer secret keys will be generated
Android Setting
- Add scribe library to android project in app/libs folder.
Add the consumer key and consumer secret key in Strings.xml file - Create an oAuth service by providing consumer key and consumer secret key to request oAuth token for authorization.
- Create an oAuth request with request method:
? For GET method:
? For POST method:
final Object being the JSONOBJECT with all required parameter values to post to API.
- Send scribe signed requests based on the async http client method to construct a signed request for oAuth service. And send the request to server.
Get Products From Woocommerce Store:
- Call the products API and pass category IDs in the URL, it will list all products of a category. It might be possible that a category has subcategories in it, in that case, pass all subcategories with the URL and all products for all subcategories mentioned in the URL will be listed
- In product response each product will have a categories array, will list categories under which the product lies, get the category name or category ID and filter products on subcategory IDs. Suppose Category 1 has three subcategories then pass all three subcategory IDs in products API.
http://your_wordpress_site/wordpress/wp-json/wc/v2/products/?category=26,27,28
Product response will have categories array:
[php]
“categories”: [
{
“id”: 26,
“name”: “Subcategory”,
“slug”: “subcategory”
}
],
[/php]
While displaying subcategory with its products, filter this list based on current subcategory we are displaying.
Leave a Reply