It looks like you're new here. If you want to get involved, click one of these buttons!
if(isset($_GET['request_token'])){
try {
$user = $kite->generateSession($_GET['request_token'], KITE_SECRET);
echo "Authentication successful. \n";
$kite->setAccessToken($user->access_token);
$connect = mysqli_connect($host, $username, $password, 'zerodha');
$saveAccessTokenQ = "UPDATE zerodha_config SET _value = '".$user->access_token."' WHERE _key = 'access_token'; UPDATE zerodha_config SET _value = '".mysqli_real_escape_string($connect, $_GET['request_token'])."' WHERE _key = 'request_token';";
;
$saveAccessToken = mysqli_multi_query($connect, $saveAccessTokenQ); //save access token to DB
} catch(Exception $e) {
echo "Authentication failed: ".$e->getMessage();
throw $e;
}
} else {
header('location: https://kite.trade/connect/login?v=3&api_key='.KITE_API);
exit();
}
Get quote file
$connect = mysqli_connect($host, $username, $password, 'zerodha');
$loadConfig = mysqli_query($connect, "SELECT _key, _value FROM zerodha_config");
while ($row = mysqli_fetch_assoc($loadConfig)) {
$config[$row['_key']] = $row['_value']; //access token loaded from DB
}
$kite = new KiteConnect(KITE_API);
$kite->setAccessToken = $config['access_token'];
try {
$quotes = $kite->getQuote($config['tickers']); //Error on this line
var_dump($quotes);
} catch(Exception $e) {
throw $e;
// requestLogin();
}
So first I visit the login page and login to Kite. This generates an access token and saves it in DB. Then I navigate to the second file and the error comes up:Fatal error: Uncaught InputException (400) 'Invalid `api_key` or `access_token`.' thrown in /home/webserver/public_html/zerodha/phpkiteconnect-kite3/kiteconnect.php on line 899
You may enable debug logs and check.
for the access token see this video
https://youtube.com/watch?v=wHLrMyzdgJw
$kite->setAccessToken($config['access_token']);
Not this
$kite->setAccessToken = $config['access_token'];
Problem solved.