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

naveen278
Team
In the below example
https://github.com/zerodha/javakiteconnect
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
https://github.com/zerodha/javakiteconnect

UserModel is not defined.
kiteSdk.setAccessToken(userModel.accessToken);
kiteSdk.setPublicToken(userModel.publicToken);

How do I get this?
Tagged:
  • SRIJAN
    SRIJAN edited May 31
    a) Api_key and api_secret can be obtained by signing up and making an app on developer console.
    https://developers.kite.trade/

    You can understand login flow here:
    https://kite.trade/docs/connect/v3/user/

    b) It's the response you get by calling generate session method.

    https://github.com/zerodha/javakiteconnect/blob/b0e847eb7feae617bafd1fc95a95dde559298722/sample/src/Test.java#L48

    https://kite.trade/docs/connect/v3/user/#authentication-and-token-exchange
  • 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.

    Regards,
    Naveen
  • SRIJAN
    SRIJAN edited June 1
    Your query has already been answered here:
    https://kite.trade/forum/discussion/11445/string-url-kitesdk-getloginurl#latest


    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?
  • SRIJAN
    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
    @SRIJAN

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

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

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

    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.