Markefanにログインを行うAPIです。
Markefanの各APIを使用するときには、最初にこのログインAPIを用いてユーザーIDやアクセストークンを取得する必要があります。
URL : [BASE URL]/SpringRest/account/user/login
Copy {
"code" : 200 ,
"message" : "LOGIN SUCCESS" ,
"status" : "OK" ,
"generatedId" : null ,
"generatedIds" : null ,
"statusObject" : "OK" ,
"account" : {
"accountId" : null ,
"name" : "" ,
"companyName" : "" ,
"companyUrl" : null ,
"creationDate" : null
} ,
"user" : {
"userId" : null ,
"name" : "" ,
"firstName" : "" ,
"lastName" : "" ,
"role" : null
} ,
"auth" : {
"accessToken" : "" ,
"tokenType" : "bearer" ,
"refreshToken" : "" ,
"expiresIn" : 3000 ,
"scope" : "[read, trust, write]"
}
}
This method used for login, you have to pass username and password as the parameter to this method and it will return the response from API. It contains users details, such as userId, accessToken etc.
Copy private String loginApi( String username , String password) {
try {
HttpClient client = new DefaultHttpClient() ;
HttpPost httpPost = new HttpPost( "<API_BASE_URL>/SpringRest/account/user/login" ) ;
List < NameValuePair > Parameter = new ArrayList < NameValuePair >();
Parameter . add ( new BasicNameValuePair( "username" , username) );
Parameter . add ( new BasicNameValuePair( "password" , password) );
HttpEntity entity = new UrlEncodedFormEntity(Parameter) ;
httpPost . setEntity (entity);
HTTPResponse response = client . execute (httpPost);
BufferedReader rd = new BufferedReader( new InputStreamReader( response . getEntity() . getContent())) ;
String line = "" ;
while ((line = rd . readLine ()) != null ) {
return line;
}
} catch ( UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e . printStackTrace ();
} catch ( ClientProtocolException e) {
// TODO Auto-generated catch block
e . printStackTrace ();
} catch ( IOException e) {
// TODO Auto-generated catch block
e . printStackTrace ();
}
return null ;
}
Copy String responseJson = loginApi( "admin" , "admin" ) ;