User user = kiteSdk.generateSession("request_token", "your_apiSecret");

In the below example
I have the API Key and LoginName

a)Were will I get the Request Token and Secret Key to generate a Session for the below?
User user = kiteSdk.generateSession("request_token", "your_apiSecret");

b) In the below example

UserModel is not defined.

How do I get this?
    SRIJAN edited May 2022
    a) Api_key and api_secret can be obtained by signing up and making an app on developer console.

    You can understand login flow here:

    b) It's the response you get by calling generate session method.
  • naveen278
    I got API key when I logged in but no secret.
  • naveen278
    I input requestoken which i got manually when I logged in along with secret in
    kiteSdk.generateSession(REQ_TOKEN_VALUE, API_SECRET);

    but it is giving Token Exception.

    SRIJAN edited June 2022
    Your query has already been answered here:

    You need to have an active KiteConnect subscription to use KiteConnect APIs . You can't use KiteConnect with Kite Publisher App which only has Api_key .
  • naveen278
    I have an active account, but I managed now but taking the request token after manually login and using in my program before it expires. But how can I ensure I dont need do this manually?
    Exchange makes it mandatory for a user to login manually atleast once a day.

    So, automatic login is not possible.

    A request token is valid for almost 5 minutes,use it immediately to get access token.
  • prashantgangurde

    I got the Access Token from below code:
    User user = kiteConnect.generateSession("asasa", "asasa");

    As per comments is stating that This access Token is valid valid for whole day right?
    But I have below observations:
    KiteConnect kiteConnect = new KiteConnect("ssasasa");
    String url = kiteConnect.getLoginURL();

    kiteConnect.setSessionExpiryHook((SessionExpiryHook) new SessionExpiryHook() {
    public void sessionExpired() {
    System.out.println("session expired");
    // Request Token, API Secret
    User user = kiteConnect.generateSession("sasa", "sasa");

    If we execute this code snippet the Java Process continues runs and never stopped.

    2. Can we use this access token for full day trade activities in other session?
    3. If we stopped the process at point 1, the Access token still valid?
    4. If we logged out and from point 1, can we still use the stored access token for other API call?
  • sujith
    The code snippet in sample code is for reference and it shouldn't be used as is without understanding.

    An app can only have one active access token at any point in time. An access token once generated can be used for whole day.

    Stopping a process will not invalidate access token unless delete access token is called explicitly or access token will be cleared everyday morning after BOD is run.

    No, if you logout in one place, you are logged out everywhere.
  • prashantgangurde
    ok, Thanks a lot for clarification.
This discussion has been closed.