session is vaid for few mins but req key is valid for almost whole day. so you can serialize usermodel parameters and deserialize it.please refer below code.
if(kiteConnect!=null) { return kiteConnect; } else { // First you should get request_token, public_token using kitconnect login and then use request_token, public_token, api_secret to make any kiteconnect api call. // Initialize KiteSdk with your apiKey. KiteConnect kiteconnect = new KiteConnect("xxx");
// set userId kiteconnect.setUserId("xxxx"); String url = kiteconnect.getLoginUrl(); System.out.println(url);
// Set session expiry callback. kiteconnect.registerHook(new SessionExpiryHook() { @Override public void sessionExpired() { System.out.println("session expired"); } });
if(kiteConnect!=null)
{
return kiteConnect;
}
else
{
// First you should get request_token, public_token using kitconnect login and then use request_token, public_token, api_secret to make any kiteconnect api call.
// Initialize KiteSdk with your apiKey.
KiteConnect kiteconnect = new KiteConnect("xxx");
// set userId
kiteconnect.setUserId("xxxx");
String url = kiteconnect.getLoginUrl();
System.out.println(url);
// Set session expiry callback.
kiteconnect.registerHook(new SessionExpiryHook() {
@Override
public void sessionExpired() {
System.out.println("session expired");
}
});
SaveToken token = new SaveToken();
UserModel userModel = null;
if(token.getFile())
{
userModel = token.deSerializeUserModel();
}
else
{
try {
userModel = kiteconnect.requestAccessToken(new Scanner(System.in).next(), "xxxxx");
} catch (JSONException | KiteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
token.serializeUserModel(userModel);
}
kiteconnect.setAccessToken(userModel.accessToken);
kiteconnect.setPublicToken(userModel.publicToken);
setKiteConnect(kiteconnect);
return kiteconnect;