d
Topic
iOS eweb a1 Member
Posts:
8
3 months ago

API access auth

I am accessing the private key URL to get the data from my shopify store.

 

When I submit that URL on chrome then it runs well. But when I am hitting that URL through my Java coding to develop Android app. It throws error 401 unauthorized. Please guide me

 

https://apikey:password@hostname/admin/resource.json

This is dummy URl, I enters my api key, passoword, hostname and run it

 

It runs well on chrome but not on android code

Please guide me

i
Replies
Nathan A Brewer Shopify Partner dftz.org
Posts:
6
3 months ago
g
1
upvotes

I have not tested this...I don't really do java. Anyway you should be using a basic authorization header instead of putting the username and password into the URI... here is an example, should get you on the right path:

String authString = "apikey:password";

byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());

String authStringEnc = new String(authEncBytes);

URL url = new URL("https://hostname/admin/resource.json");

URLConnection urlConnection = url.openConnection(); urlConnection.setRequestProperty("Authorization", "Basic " + authStringEnc); InputStream is = urlConnection.getInputStream();

iOS eweb a1 Member
Posts:
8
3 months ago

@Nathan

 

Thanks it worked.