API Authentication problem in my android app.

edited May 2015 in Questions
I'm trying to connect with below code.

==============================================================================================
// Your Site Settings
String site_subdomain = "hunuyi";
String site_public_key = "79bf0cd7-8440-4344-a16b-000000000000";
String site_private_key = "*****";

// API Access Domain
String site_domain = site_subdomain + ".api.oneall.com";

// Connection Resource
String resource_uri = "https://" + site_domain + "/connections.json";

// Result Container
String result_json = "";
String result = null;

if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}

try
{
// Forge authentication string username:password
String site_authentication = site_public_key + ":" + site_private_key;
String encoded_site_authentication = new String(Base64.encode(site_authentication.getBytes(), Base64.DEFAULT)).replaceAll("[\n\r]", "");

// Setup connection
URL url = new URL (resource_uri);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();

// Connect using basic auth
connection.setRequestMethod("GET");
connection.setRequestProperty("Authorization", "Basic " + encoded_site_authentication);
connection.setDoOutput(true);
connection.setReadTimeout(10000);
connection.connect();
connection.getInputStream();

StringBuilder sb = new StringBuilder();
String line = null;

// Read result
BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
while ((line = rd.readLine()) != null) {
sb.append(line);
}
result = sb.toString();

}
catch (Exception e)
{
e.printStackTrace();
}
==============================================================================================

It occurs exception that is "java.io.FileNoFoundException: https://hunuyi.api.oneall.com/connections.json".

Is the problem because of my account plan?

Answers

  • Hi,

    Do you still experience the error ?
    If so, can you provide the io exception message details ? (the URL seems valid)

    Regards

Welcome!

Please sign in to your OneAll account to ask a new question or to contribute to the discussions.

Please click on the link below to connect to the forum with your OneAll account.