302 temporarily moved url
pannet1 opened this issue · 12 comments
Hi,
During the login flow I am getting 302 error for this url https://kite.zerodha.com/connect/authorize?sess_id=secret_session_id&v=3 and 2 more subsequent redirects.
Is this API working or not. Now I am struck between old and new version
How is this related to phpkiteconnect? phpkiteconnect just gives login URL.
Are you automating login?
sujith,
i have signed up for zerodha kite api. I have been already using the earlier version of the phpkiteconnect and it was working successfully. now i have updated to the latest phpkiteconnect and i am unable to do the same. I am just following the code example to rename the old working code and it fails.
how to troubleshoot this and tell you the problem.
Have you updated to Kite 3 version from branch? If yes then you can check CHANGELOG.md file which list all the changes need to be made to migrate. Please enable debug on and post your logs.
vivek @vividvilla,
i already did ..
for example changed from old code to
$oUser = $oKite->generateSession($request_token,$f3->get('api_secret'));
i get the login page and then after success i get the error
Missing access_token [public_html/kiteconnect.php:647]
Error code: 500
Can you please share your part of code where you are doing this flow? (Please make sure to remove api_key and api_secret if any)
vivek @vividvilla
the registered return url is https://example.com
login_controller
`public function index($f3) {
$f3->set('nav','Positions' );
// Incoming from the redirect.
if($f3->exists('GET.request_token')) {
$request_token = $f3->get('GET.request_token');
$oKite = new KiteConnect($f3->get('api_key'));
try {
$oUser = $oKite->generateSession($request_token,$f3->get('api_secret'));
$oKite->setAccessToken($oUser->access_token);
// set session variables
$f3->set('SESSION.oKite',$oKite);
$f3->set('SESSION.user_user_id', $oUser->user_id);
$f3->set('SESSION.user_access_token', $oUser->access_token);
$f3->set('SESSION.user_public_token', $oUser->public_token);
// if no route present in cookie
if( empty($f3->get('COOKIE.route') ) ) {
// set default route here
$f3->set('COOKIE.route','/positions');
$f3->reroute($f3->get('kiteurl'));
} else { // found cookie refresh this page
$f3->reroute($f3->get('COOKIE.route'));
}
} catch(Exception $e) {
echo "Authentication failed: ".$e->getMessage();
throw $e;
}
} else { // if exist request_token
$f3->error(404);
}`
postions_controller (part code)
` public function index($f3) {
$user = $f3->get('SESSION.oUser');
// access token is missing in this kite object
print_r($this->kite);
if(!$f3->get('COOKIE.route')) {
$f3->set('COOKIE.route','/positions');
$f3->clear('SESSION');
$f3->reroute($f3->get('kiteurl'));
} else {
$positions = $this->kite->positions();`
Please follow these steps and report
- Check if kiteconnect.php is updated to latest from Kite3 branch.
- Print variable $request_token and check if its actually returned from Kite redirect.
- Along with $request_token you need to also get variable $status from redirect and check if its value is
success
.
Also you have previously said that you are getting 302 redirect. This is normal if your app is not authorized and it will show authorization page which user has to click authorize and it will redirect to your app redirect url. Please make sure that you are not missing that part.
Vivek @vividvilla,
My >> Inputs below in lower Case
Check if kiteconnect.php is updated to latest from Kite3 branch.
yes. it is updated. i checked the head on the 6 line it says version 3. also the login page url has &ver3
Print variable $request_token and check if its actually returned from Kite redirect.
i checked and verifed there is a match
Along with $request_token you need to also get variable $status from redirect and check if its value is success.
i can see last redirect url having the line https://example.com?status=success&request_token=iBpejxy1fRwTakJAVePMKlbKv3vGlYti
Also you have previously said that you are getting 302 redirect. This is normal if your app is not authorized and it will show authorization page which user has to click authorize and it will redirect to your app redirect url. Please make sure that you are not missing that part.
i never received a authorization page, but i could see 1 of 4 redirected pages having the following url, from the developer pane
https://kite.zerodha.com/connect/authorize?sess_id=aar9woxkq6xr1x3jlidyf2119hyqvsqx&v=3
Is this correct?
hi vivek @vividvilla
any ideas ?
I just did a simple example with your api_key
and I was able to generate access token. Here is my example.
// Initialise.
$kite = new KiteConnect("your_api_key", null, null, true);
$secret = "your_api_secret";
$request_token = "your_request_token"
try {
$user = $kite->generateSession($request_token, $secret);
echo "Authentication successful. \n";
print_r($user);
exit;
$kite->setAccessToken($user->access_token);
} catch(Exception $e) {
echo "Authentication failed: ".$e->getMessage();
throw $e;
}
Also your error message says this
Missing access_token [/var/www/clients/client0/web29/web/fatfree-36/kiteconnect.php:647]
But you can see that line 647 is not a valid method or anything in source - https://github.com/zerodhatech/phpkiteconnect/blob/kite3/kiteconnect.php#L647
Seems like you still haven't updated kiteconnect.php file
hi vivek @vividvilla,
there was a new update ver 3b) last monday. after updating now i have success. Thank you.
please advise how to access the quotes after getting it like this
$oQuote = $this->kite->getQuote( $items->get('exchange').":".$items->get('tradingsymbol') );
earlier i was able to access it with
$oQuote->last_price $oQuote->ohlc->high
now since the new api had introduced $i into the mix, please advise on how to get the quotes.