It looks like you're new here. If you want to get involved, click one of these buttons!
<?php
include "KiteConnect.php";
//Got the apikey and apisecrete from my application.
$apikey = "xxxxxxxxxxx";
$apisecret="yyyyyyyyyyyyyyyyy";
//Get Request token from the following URL
//https://kite.zerodha.com/connect/login?api_key=xxxxxxxxxxx
$requesttoken="XXXXXX";
try {
// Initialise.
$kite = new KiteConnect($apikey);
return;
// the program exits with this 'KiteConnect($apikey)' statement. It won't go further.
//$user = $kite->generateSession($requesttoken, $apisecret);
}
catch(Exception $e) {
echo 'Message: ' .$e->getMessage();
}
?>
Where I am making the mistake?
You can go through the PHP example here.
This is the error message I am getting.
From the example you have referred.. I haven't used the
require_once __DIR__ . '/vendor/autoload.php';
bit.Is this the main problem?
I am not sure about it. What is the autoload.php? What it does? How do I download and use it?
Thanks.
After I installed composer in the same folder, I am able to move forward to
$kite = new KiteConnect($apikey);
I obtained my request token from
https://kite.trade/connect/login?api_key=xxxxxxxxx
When I used this requesttoken along with secret key obtained from my APP page the page is not working....
<?php
require_once __DIR__ . '/composer/vendor/autoload.php';
use KiteConnect\KiteConnect;
//Got the apikey and apisecrete from my application.
$apikey = "xxxxxxxxxxx";
$apisecret="yyyyyyyyyyyyyyyyy";
//Get Request token from the following URL
//https://kite.trade.com/connect/login?api_key=xxxxxxxxxxx
$requesttoken="zzzzzzzzzzz";
try {
// Initialise.
$kite = new KiteConnect($apikey);
echo "KiteConnect successful";
// the program works upto this nicely.
$user = $kite->generateSession($requesttoken, $apisecret);
echo "Authentication successful. \n";
//This line is not working....... Session is not generated. (Please help me)
}
catch(Exception $e) {
echo 'Message: ' .$e->getMessage();
}
?>
<?php
require_once __DIR__ . '/vendor/autoload.php';
use KiteConnect\KiteConnect;
$api_key = "8rdzulnifq8kd99q";
$api_secret="fkmiwzvddvo6487s0rovpas1haafyik3";
$request_token="Fit2yBqFsUaoDQlJYL6JGXE3a8Gmw2zC";
try {
$kite = new KiteConnect($api_key);
echo "KiteConnect OK";
$user = $kite->generateSession($request_token, $api_secret);
echo "Authentication successful. \n";
print_r($user);
return;
}
//catch exception
catch(Exception $e) {
echo 'Message: ' .$e->getMessage();
}
?>
The above is the whole code. "KiteConnect OK" is echoing. But generateSession is not working.
Please help.
Also, if you want to use the current PHP client, please upgrade to PHP >=8.
If the
$user = $kite->generateSession($request_token, $api_secret);
is removed, the page is working.Thanks.
Message: Connection refused for URI https://api.kite.trade/session/token
Currently I am using PHP 8.0.7 and Composer/KiteConnect v4.
Suppose, if I need to go to v3, I understand that PHP >7.3. If so, should I uninstall composer and reinstall with v3? Or just copying v3-KiteConnect.php is enough?
try {
$user = $kite->generateSession($request_token, $api_secret);
$kite->setAccessToken($user->access_token);
} catch(Exception $e) {
echo "Authentication failed: ".$e->getMessage();
throw $e;
}
//maybe this try catch block will give you an error.