Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
TejaVarma
9 years agoExplorer | Level 4
java.net.UnknownHostException
Unable to resolve host "api.dropboxapi.com": No address associated wi
TejaVarma
9 years agoExplorer | 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 Community Moderator
9 years agoThanks! 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.
- TejaVarma9 years agoExplorer | 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-DB9 years ago
Dropbox Community Moderator
https://api.dropboxapi.com/oauth2/token is the correct URL. You can find the current documentation here:
https://www.dropbox.com/developers/documentation/http/documentation#oauth2-token
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!