Getting message: 'Token is invalid or has expired.'

RASCAL005
RASCAL005 edited October 2019 in API clients
I have tried generating access token but getting the error message: 'Token is invalid or has expired.', I even tried to logout using sessionhook, but still its giving the error, What to do if access token is already generated and I did not save it, how to generate it again? @sujith
user - KT3559
  • sujith
    If you lose an access token then you need to re-login and get another request token.
    You can create a new access token with the new request token.
  • RASCAL005
    RASCAL005 edited October 2019
    I am trying to do that, but its giving the error message: 'Token is invalid or has expired.',
    I am able to generate the request token successfully, but the generateaccess token is giving error

    {
    status: 'error',
    message: 'Token is invalid or has expired.',
    data: null,
    error_type: 'TokenException'
    }
  • RASCAL005
    RASCAL005 edited October 2019
    function call_kite_api(token, res) {

    var param_code = token.query.request_token;
    console.log(param_code);

    var api_key = "##########",
    secret = "###############",
    request_token = param_code,
    access_token = "";

    var options = {
    "api_key": api_key,
    "debug": false
    };

    kc = new KiteConnect(options);
    kc.setSessionExpiryHook(sessionHook);

    function sessionHook() {
    console.log("User loggedout");
    }

    if (!access_token) {
    kc.generateSession(request_token, secret)
    .then(function(response) {
    console.log("Response", response);
    access_token = response.access_token;
    kc.setAccessToken(access_token);
    })
    .catch(function(err) {
    console.log(err);
    })
    } else {
    kc.setAccessToken(access_token);
    //init();
    }

    res.json('success');

    }
    @sujith am I missing something here.?
  • sujith
    You can refer this thread.
  • RASCAL005
    RASCAL005 edited October 2019
    Hi @sujith , the thread you referred did not help, please try to generate access token at your end for this user, if possible. Else please help me in debugging the issue.
  • RASCAL005
    Hi @sujith , it worked, issue was at my end, thanks for your help :smile:
This discussion has been closed.