https://github.com/fujiriko59/nico-api-client
I used the one in, but I was throwing errors related to cookies and XML parsing, so I decided to make it from scratch. Since I used Gladle on Android, I decided to manage the project with Gladle. Will be released at a later date.
I had been going back and forth for several hours,
https://teratail.com/questions/31972
It worked when I referred to Unfortunately, I have no Http-related knowledge **.
Login
public static void login_test_from_teratail(){
try {
URI uri = new URI("https://secure.nicovideo.jp/secure/login?site=niconico");
String mail = "Address here";
String pass = "Password here";
HttpPost httpPost = new HttpPost(uri);
RequestConfig requestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build();
httpPost.setConfig(requestConfig);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("mail", mail));
params.add(new BasicNameValuePair("password", pass));
httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
HttpClient httpClient = HttpClientBuilder.create().build();
HttpResponse httpResponse = httpClient.execute(httpPost);
//POST result
String response1 = httpResponse.toString();
String response2 ="";
for (String str : response1.split(",",0)){
response2 += str+"\n";
}
System.out.println(response2);
}catch (Exception e){
e.printStackTrace();
}
}
In the comment, I pointed out that Apache's HttpClient is deprecated, so I decided to use CustomHttpClient by myself using HttpURLConnection. However, here too, there are many cookie-related problems. After investigating, there seems to be such a problem. --The expiration date of cookies is set to 0 by setting the time for each region (solved as of 03/02/2017) --Cookie data is stacked and the priority is reversed (unresolved)
As a result, the Session ID cannot be obtained correctly. Therefore, I decided to use Class from the following site.
http://tomott.cocolog-nifty.com/blog/files/CorrectedCookieManager.java
Quote: http://tomott.cocolog-nifty.com/blog/2010/09/javecookie5-5d9.html
It's been a while since the last edit. Describe what you remember.
When I prepare a cookie and hit the URL of the video directly, 403 is returned. So before that you need to access some URl.
An issue where builds and executions fail when the total number of methods exceeds 64K.
https://developer.android.com/studio/build/multidex.html
There was a good article so I will refer to it
http://qiita.com/mogulla3/items/189c99c87a0fc827520e
http://www.binzume.net/diary/2010-10-04:A1
As written in, I thought that I was in trouble because I could specify Uri but not cookies, but when I looked at the Android Developer site,
setVideoURI
void setVideoURI (Uri uri, Map<String, String> headers)
Was added at API Level 21. This seems to be a solution.