Access token is getting expired frequently

r2k1984
Hi,

I have created a access token and it gets expired every call. Token is getting expired for every call.

I'm not sure why there is a issue.
  • rishiswethan
    rishiswethan edited August 29
    import dill

    file_to_dump_file = open(config.KITE_OBJECT_FILE, "wb")
    dill.dump(kite, file_to_dump_file) # kite being the object you set access token to
    file_to_dump_file.close()

    Store it like this after loading the access token
  • rakeshr
    @r2k1984
    No, access_token doesn't expire after every API request. Once you have generated access_token, store it in variable and keep using it for other API calls throughout(until performing logout or fresh login).
  • nikhilbansal
    @r2k1984

    Access token once received never expires for 24 hours untill its flushed and cleaned by zerodha daily in morning at around 7:30. You can store that token and reuse.

    Thanks
    Regards,
    Nikhil Bansal
    Tritan Solutions Pvt. Ltd.
  • ZI4453
    @r2k1984
    i suspect you might have issues due to global/local values, please check your codes once again, may be data path from access generated to access expiry will give you where you went wrong.....
  • r2k1984
    <?php
    $output = "json_token.json";
    $access_token = $_GET['request_token'];
    echo $access_token;
    $json['access_token'] = $access_token;
    $json = json_encode($json);
    file_put_contents($output, $json );
    ?>

    This is the code I'm receiving and storing the data in the access_token in JSON. When i consume the access token the buyorder example.php . It is not working at all.

    We are not sure whether it is working correctly.

  • r2k1984
    <?php

    include dirname(__FILE__)."/kiteconnect.php";
    $kite = new KiteConnect("access token here");

    ?>

    Could someone provide actual code to store the access token or refersh it.
  • hitman1980
    I have set my login process like this ..


    $apikey=$adminline['apikey'];
    $rtok=$_GET['request_token'];
    $kite = new KiteConnect($apikey);
    $url = $kite->getLoginURL();
    if($rtok=="")
    {
    header("Location: $url");
    exit;
    }
    else
    {
    $user = $kite->generateSession($rtok, $adminline['apisecretkey']);
    $userdb=serialize($user);
    $atok = $user->access_token;
    $kite->setAccessToken($accesstoken);
    $insert=mysqli_query($link,"update config_settings set accesstoken='".$atok."', userdetails='".$userdb."'");



    Now with accesstoken in database .. U can fetch whtever data u want from the API feed ..
  • r2k1984
    I have stored the same in the database and using it by the example in php libraries they have provided. But every time I use the token it is getting expired. So every time I have to call the API url and get the toekn for the same.

    Not sure where is the issue.
  • r2k1984
    We are able to fix the issue as the generate session was causing issue.
  • hitman1980
    So once the token is stored in database.. than u have to declare the new KiteConnect instance and call setAccessToken with the token key ..

    For example lets say now the token is stored in ur database.. so to start using the api u have to declare a new instance as below .. and once it is done than only u can use lib functions they have given .. U can't use functions like $kite->getQuote etc without making a call to setAccessToken ..

    So basically on top of ur page it should be in place .. below tht u can work on ur code ..


    $accesstoken=$adminline['accesstoken'];
    $apikey=$adminline['apikey'];
    $kite = new KiteConnect($apikey);

    $kite->setAccessToken($accesstoken);

    $kt=$kite->getQuote(["738561"]);
Sign In or Register to comment.