Along with rolling out a Python adapter for the Shopify API we'd also like to announce a new Java binding: Shopify4J
This is an Android-compatible library which provides an easy way for Java developers interact with Shopify. We’ve taken care of creating all the Java beans, and API endpoints that you as a developer would need to deal with yourself.
Here is a little example showing how easy it is to use Shopify4J to get a list of products for a shop:
import java.util.List;
import com.shopify.api.client.ShopifyClient;
import com.shopify.api.credentials.Credential;
import com.shopify.api.credentials.JsonDirectoryCredentialsStore;
import com.shopify.api.endpoints.ProductsService;
import com.shopify.api.resources.Product;
public class S4JDemo {
private ShopifyClient shopify;
public S4JDemo(){
// Let's pretend we are just using a developer key for now
Credential creds = new Credential("my-api-key", "my-shared-secret", "my-shopify-shop", "my-password");
shopify = new ShopifyClient(creds);
}
public void run() {
// Create a "Products Service" from our client. This is what makes the API calls to /admin/products
ProductService productsApi = shopify.constructService(ProductsService.class);
// Get a list of products for our store -- this is a blocking operation
List products = productsApi.getProducts();
// Print out product information to the terminal
for(Product p : products){
String message = String.format("%s is made by %s" , product.getTitle(), product.getVendor());
System.out.println(message);
}
}
public static void main(String[] args){
S4JDemo demo = new S4JDemo();
demo.run();
}
}
/*****************************
* Example output:
* iPhone is made by Apple
* Nexus One is made by HTC
* PlayBook is made by BlackBerry
*******************************/
We'd like to thank the maintainers of Codegist CRest and the Jackson JSON parser for providing awesome tools.
Topics:
Join 379,633 entrepreneurs who already have a head start.
Get free online marketing tips and resources delivered directly to your inbox.
Thanks for subscribing
You’ll start receiving free tips and resources soon. In the meantime, start building your store with a free 14-day trial of Shopify.