I want to access MS cloud api on android flatform.
So I found one sample app.
Here is sample app which work this function. (https://github.com/adithya321/Companion-for-Band/blob/dev/app/src/main/java/com/pimp/companionforband/activities/cloud/WebviewActivity.java)
I made MS application from dev.app.microsoft.com
and made password and register web platform rediret uri(https://login.live.com/oauth20_desktop.srf)
So I had my client_id, client_serect
In downloreUrl function, RequestMethod is "GET". So, I changed it to "POST".
private String downloadUrl(String url) throws IOException {
InputStream is = null;
try {
URL u = new URL(url);
HttpURLConnection conn = (HttpURLConnection) u.openConnection();
conn.setReadTimeout(10000);
conn.setConnectTimeout(15000);
conn.setRequestMethod("GET");
conn.setDoInput(true);
conn.connect();
is = conn.getInputStream();
return readIt(is, 9999);
} finally {
if (is != null) {
is.close();
}
}
but it doesn't work this app.
I changed accessing method using HttpClient, not HttpURLConnection .
I found that I access to MS cloud api with public client.
here is logcat
02-10 15:30:51.533 29336-29639/com.example.user.bandsample D/WebviewActivity: executeClient: {"error":"invalid_request","error_description":"Public clients can't send a client secret."}
Deleting client_secret, I just got access_token without refresh token.
I don't know what should I do.
I solved the problem.
First, If you made mobile app from Application center, you don't need client_secret.
I changed code URLConnection to HttpClient. URLConnection is more simple but it doesn't working.
add this code from gradle android for using HttpClient
and change code Downloadurl to new code
and I used StringRequest instead of JsonObjectRequset