Session Expired

parikh
Team,

I am getting session expired on connection. Any hints to get this solved.

Note: I am using new request token everytime I initiate a session.
Tagged:
  • sujith
    Hi,
    An access token is valid for one whole day. Once you get access token, you don't have to request for it again unless you are logged out.
    A request token is valid for a couple of minutes and can be used only once. You should not request for access token for every run.
    Once you get access token store it in a file or app preferences and re-use it
  • hardikdesai
    @sujith : I have created a session and an access token in morning. However when i tried to use the same session in afternoon i got a : KiteException: com.zerodhatech.kiteconnect.kitehttp.exceptions.TokenException

    As suggested by you i am creating a session and an access token only once for a day, but looks like the session and token does not remain active for the entire day.

    Can you please suggest?
  • shailu
    Even though i logged in at around 930/10 am, this happens with me, yesterday at 3PM, i got
    com.zerodhatech.kiteconnect.kitehttp.exceptions.TokenException.
  • sujith
    @hardikdesai, @shailu,
    Are you sure you didn't log in to PI or NEST?
    If you log out from any platform then you might be logged out everywhere.
  • paragsatpute
    paragsatpute edited July 2018
    @sujith,
    After the login completion i get the access token and the authentication is successful but, soon after the code is completed executing the code i have to again re-login if i refresh the same webpage and i get the error as "Authentication failed: Token is invalid or has expired."

    Please advise on how i can keep the access token, public token etc. for the session alive so that i do not have to login for each refresh.

    This is bit frustrating as i am writing and testing my code. Below is my code i am working on in PHP,

    =========================================================

    // Initialise for KiteConnect
    $apikey = "ABC";
    $apisecret = "XYZ";
    $tempkite = new KiteConnect($apikey);

    if(isset($_GET["request_token"])){
    $request_token = $_GET["request_token"];
    //echo "Token is: ".$request_token."\n";
    }else{
    header("Location: ".$tempkite->getLoginURL());
    exit();
    }

    try {
    $user = $tempkite->generateSession($request_token, $apisecret);
    echo nl2br("Authentication successful. \r\n \r\n");
    $tempkite->setAccessToken($user->access_token);
    } catch(Exception $e) {
    echo "Authentication failed: ".$e->getMessage();
    throw $e;
    }

    =========================================================
  • sujith
    Make sure you store access token in preferences or database and re-use it in the next run and don't call generateSession for every run.
  • gjmaster
    yes but not working just expired when refresh my page with same access token which is stored in database.
  • sujith
    Do you use Pi or NEST?
  • ajay_varma
    actually me too facing the same issue
    my access_token is expiring frequently. on the other hand, my friends token remains active for the whole day
    we both are using the same logic and same coding. i didnt made any changes in my code and since 2 months its working perfectly. just i was required to update the token early morning daily. but since today, my token is expiring within a minute or two.

    i tried it using in my localhost server(local system files), token works fine, but it expires only if i update it on my server files...

    please help me brother
    email [email protected]
  • VICKY123
    me too facing same problem..my request token is expiring within a minute or two.
  • sujith
    @VICKY123,
    Please read my comment about the request token.
  • infotrade
    @sujith ,
    A request token is valid for a couple of minutes and can be used only once. You should not request for access token for every run.
    Once you get access token store it in a file or app preferences and re-use it.

    You said that token can be used only once and also mentioned that you can re-use it. Can you please clarify your statement here?

    I am storing Token is local system and when I try to re-use it, it throws an exception to re-login again.


  • Imran
    hii @ infotrade

    go through this video
    https://youtube.com/watch?v=wHLrMyzdgJw
  • infotrade
    Thanks. I got it now. I was confused between request token and response token.
This discussion has been closed.