Invalid `checksum for kite api php v3

gautam_s60
gautam_s60 edited January 2018 in PHP client
The request token received is : hXUDqyoSDuqNqs2l5tCXvVX5lhsfDFRR
Authentication failed: Invalid `checksum`.
Fatal error: Uncaught TokenException (403) 'Invalid `checksum`.' thrown in C:\xampp\htdocs\dashboard\kiteconnect.php on line 918

my code for authentication
--------------
<?php
$start_tm= date('g:i s a');
echo '<br/>';
include dirname(__FILE__)."/kiteconnect.php";
//include dirname(__FILE__)."/call_td_imp.php";

$servername = "localhost";
$apk="xxxx";
$kite = new KiteConnect("xxxx");
$api_secret = "yyyy";
echo "The request token received is : ".$_GET["request_token"]."
";
$request_token = $_GET["request_token"];
//$acctkn=$_GET["access_token"];
try {
$user = $kite->generateSession($request_token, $apk);
// $user = $kite->requestAccessToken($request_token, $api_secret);

echo "Authentication successful. \n";
print_r($user);

$kite->setAccessToken($user->access_token);
} catch(Exception $e) {
echo "Authentication failed: ".$e->getMessage();
throw $e;
}
echo $user->user_id." has logged in";
echo $user->access_token." has logged in";
$acctkn=$user->access_token;
$pbtkn=$user->public_token;

$myfile=fopen("tkns.txt","w");
$txt=$apk.$api_secret.$request_token.$acctkn.$pbtkn;
fwrite($myfile,$txt);
fclose($myfile);

$myfile1=fopen("tkns1.txt","w");
$txt1=$apk.','.$api_secret.','.$request_token.','.$acctkn.','.$pbtkn;
fwrite($myfile1,$txt1);
fclose($myfile1);
?>
  • sujith
    Are you sure you are sending right api_key and api_secret?
  • Kailash
    @gautam_s60

    $user = $kite->generateSession($request_token, $apk);.

    The second parameter here should be the api_secret You're sending the api_key.
  • gautam_s60
    that is corrected, memory cleared and re checked, but still same error
    ____________

    <?php
    $start_tm= date('g:i s a');
    echo '<br/>';
    include dirname(__FILE__)."/kiteconnect.php";
    //include dirname(__FILE__)."/call_td_imp.php";

    $servername = "localhost";
    $api_k="xxx";
    $kite = new KiteConnect($api_k);
    $as = "yyy";
    echo "The request token received is : ".$_GET["request_token"]."
    ";
    $request_token = $_GET["request_token"];
    try {
    $user = $kite->generateSession($request_token, $as);

    echo "Authentication successful. \n";
    print_r($user);

    $kite->setAccessToken($user->access_token);
    } catch(Exception $e) {
    echo "Authentication failed: ".$e->getMessage();
    throw $e;
    }
    echo $user->user_id." has logged in";
    echo $user->access_token." has logged in";
    $acctkn=$user->access_token;
    $pbtkn=$user->public_token;


    $myfile=fopen("tkns.txt","w");
    $txt=$api_k.$as.$request_token.$acctkn.$pbtkn;
    fwrite($myfile,$txt);
    fclose($myfile);

    $myfile1=fopen("tkns1.txt","w");
    $txt1=$api_k.','.$as.','.$request_token.','.$acctkn.','.$pbtkn;
    fwrite($myfile1,$txt1);
    fclose($myfile1);
    ?>
  • Vivek
    I just tested your script by replacing `request_token` with request token I got from my app and it works. Here is my code for your reference. Please check if you are passing right api secret and request token
    <?php
    $start_tm= date('g:i s a');
    echo '<br/>';
    include dirname(__FILE__)."/kiteconnect.php";
    //include dirname(__FILE__)."/call_td_imp.php";

    $servername = "localhost";
    $api_k="your api key";
    $as = "your api secret";

    $kite = new KiteConnect($api_k);
    $request_token = "some access token received";

    try {
    $user = $kite->generateSession($request_token, $as);

    echo "Authentication successful. \n";
    print_r($user);

    $kite->setAccessToken($user->access_token);
    } catch(Exception $e) {
    echo "Authentication failed: ".$e->getMessage();
    throw $e;
    }
    echo $user->user_id." has logged in";
    echo $user->access_token." has logged in";
    ?>
  • gautam_s60
    thanks for the code. error was due to sessions conflict btwn v1 and v3.
    but even after different successful token exchange.
    i got error while holdings call.
    curl :
    https://api.kite.trade/portfolio/holdings/?api_key=myapi&access_token=my access token&rand=0.24&v=3

    {"status": "error", "message": "That API call is not allowed for the authenticated user", "error_type": "PermissionException"}"
  • sujith
    All the Kite Connect 3 endpoints require X-Kite-Version:3 in header. Please go through documentation once to avoid this kind of issues.
    The query param v=3 is only for login URL and not for others.
Sign In or Register to comment.