cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

java.net.UnknownHostException

java.net.UnknownHostException

TejaVarma
Explorer | Level 4

Unable to resolve host "api.dropboxapi.com": No address associated wi

5 Replies 5

Greg-DB
Dropbox Staff

@TejaVarma It looks like you didn't post the entirety of the issue. Can you share the code and full output that's giving you trouble?

 

Based on what you did post though, it looks like you're getting a UnknownHostException for api.dropboxapi.com.

 

Per the documentation for java.net.UnknownHostException this error indicates:

 

"... that the IP address of a host could not be determined."

 

So, it sounds like you may be having DNS issues, preventing you from resolving the Dropbox API servers. The Dropbox API servers are resolving correctly though, so this sounds like an issue with your network connection.

 

Is there any reason your app might not be able to resolve the Dropbox API servers? For example, I recommend checking any firewall, proxy, or security software that may be interfering with your network connection. Likewise, you may need to check that your DNS server is working properly.

TejaVarma
Explorer | Level 4

Here is code 

 

String urlToken = "https://api.dropboxapi.com/oauth2/token";
String charset = "UTF-8"; // Or in Java 7 and later, use the constant: java.nio.charset.StandardCharsets.UTF_8.name()
String query = String.format("grant_type=authorization_code&%s&code=%s&client_id=%s&client_secret=%s",
"redirect_uri=https://192.168.137.129:8080/0/rest/cloudAdded?provider=dropbox",
URLEncoder.encode(authCode, charset),
URLEncoder.encode(APP_KEY, charset),
URLEncoder.encode(APP_SECRET, charset));
Log.d(LOG_TAG, "getInputStreamAsString()");
String inputStreamAsString = AccountsManager.getInputStreamAsString(urlToken, charset, query);

String result = "";
try{
URL url = new URL(urlStr);
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();

// Create the SSL connection
/*SSLContext sc;
sc = SSLContext.getInstance("TLS");
sc.init(null, null, new java.security.SecureRandom());
conn.setSSLSocketFactory(sc.getSocketFactory());*/

// set Timeout and method
conn.setReadTimeout(15000);
conn.setConnectTimeout(15000);
conn.setUseCaches(false);
conn.setDoInput(true);
conn.setDoOutput(true); // Triggers POST.

conn.setRequestProperty("Content-Language", "en-US");
conn.setRequestProperty("Accept-Charset", charset);
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
// conn.setRequestProperty("Content-Length", "" + Integer.toString(_charset.getBytes().length));

OutputStream os = conn.getOutputStream();
os.write(query.getBytes(charset));
os.close();

conn.connect();

/*
String err = new String();
InputStream errStream = conn.getErrorStream();
BufferedReader errReader = new BufferedReader(new InputStreamReader(errStream));
String eLine;
while ((eLine = errReader.readLine()) != null) {
err += eLine;
}
Log.e(LOG_TAG, "ERROR : " + err);
*/

Log.d("", "getInputStreamAsString() : responseCode: " + conn.getResponseCode() +
"response message : " + conn.getResponseMessage());

//read the inputStream into a string
result = new String();
InputStream is = conn.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(is));
String inputLine;
while ((inputLine = in.readLine()) != null) {
result += inputLine;
}
} catch (Exception e) {
Log.w("", "Exception thrown " + e.getMessage());
throw new UnsupportedOperationException("TODO : handle this");
}

Most of the time code is working fine. But Some time I am getting error.


Greg-DB
Dropbox Staff

Thanks! By the way, it looks like you're not using the official Dropbox API v2 Java SDK. We do highly reccomend using it, if possible.

 

In any case, whether or not you're using it, it does just look like this error is due to intermittent DNS issues, so you should look into why your DNS queries may be failing occasionally.

TejaVarma
Explorer | Level 4

 

I am using Dropbox API v2 libary, instead of using Auth, I am using API directly.  I cahnged url from v1 to v2. From this url https://www.dropbox.com/developers/reference/migration-guide 

 

I changed url /1/oauth2/token to /oauth2/token

 

Right now it is working fine. By changing WIFI settings. If I face same problem I will let you know.

 

Please confirm weather I am using correct URL of V2 or not?

Greg-DB
Dropbox Staff
Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    TejaVarma Explorer | Level 4
What do Dropbox user levels mean?