Hi,
This is the code I am using
try {
/**
* Changed URL from dropbox oauth 1 to 2
*/
// String urlToken = "https://api.dropboxapi.com/1/oauth2/token"; api.dropboxapi.com
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));
String inputStreamAsString = AccountsManager.getInputStreamAsString(urlToken, charset, query);
JSONObject json = new JSONObject(inputStreamAsString);
if (json.has("access_token"))
token1 = json.getString("access_token");
Log.d(LOG_TAG, "TODO - REMOVE THIS - dropbox core api returned - TOKEN:" + token1);
if (json.has("uid"))
uid1 = json.getString("uid");
Log.d(LOG_TAG, "Dropbox Core API returned - UID:" + uid1);
} catch (Exception e) {
Log.w(LOG_TAG, "Exception thrown " + e.getMessage());
throw new UnsupportedOperationException("TODO : handle this");
}
getInputStreamAsString Code
public String getInputStreamAsString(String urlStr, String charset, String query)
throws IOException, NoSuchAlgorithmException, KeyManagementException
{
String result = "";
try{
URL url = new URL(urlStr);
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
// 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");
OutputStream os = conn.getOutputStream();
os.write(query.getBytes(charset));
os.close();
conn.connect();
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");
}
return result;
}
Please suggest me when we will get java.lang.UnsupportedOperationException
Thanks.