Official PHP client for Kite Connect is out

  • jitendra
    While Login, I am getting the following error:

    Authentication failed: Invalid session credentials
    Fatal error: Uncaught TokenException (403) 'Invalid session credentials' thrown in C:\xampp\htdocs\kiteconnect.php on line 529


    Even though I am not Logged-In in any other system.
  • Kailash
    Please share the code snippet you're trying. You are getting the request_token after the login redirect and obtaining an access_token, yes?
  • jitendra
    Yes. I am able to login and getting the request token and access token. Please find the code:

    include "kiteconnect.php";
    $kite = new KiteConnect("$api_key");
    try {
    $user = $kite->requestAccessToken("$request_token", "$secret_key");

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

    $kite->setAccessToken($user->access_token);
    } catch(Exception $e) {
    echo "Authentication failed: ".$e->getMessage();
    throw $e;
    }
  • Kailash
    Please don't enclose $variables in quotes. For example, `new KiteConnect($api_key);`

    Where is $request_token's value being set in your example?
  • amanrawat
    amanrawat edited May 2016
    I have encountered with the same problem. Here is my code

    <?php

    $apiKey = 'xxxxxx';
    $token = $_GET['request_token'];
    $apiSecret = 'xxxxxx';
    include dirname(__FILE__) . "/kiteconnect.php";

    // Initialise.
    $kite = new KiteConnect($apiKey, null, null, true);

    // Assuming you have obtained the `request_token`
    // after the auth flow redirect by redirecting the
    // user to $kite->login_url()
    try {
    $user = $kite->requestAccessToken($token, $apiSecret);

    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";


    and i am getting a response

    Request: https://api.kite.trade/session/token array(3) { ["request_token"]=> string(32) "xxxxxxxxx" ["checksum"]=> string(64) "xxxxxxxxxxxxxxxxx" ["api_key"]=> string(16) "xxxxxxx" } Response :{"status": "error", "message": "That API call is not allowed for the authenticated user", "error_type": "PermissionException"} Authentication failed: That API call is not allowed for the authenticated user
    Fatal error: Uncaught PermissionException (403) 'That API call is not allowed for the authenticated user' thrown in F:\public_html\kite\kiteconnect.php on line 668

    Hoping for a quick reply
  • Kailash
    Have you created a Publisher app or a Connect app? Only Connect apps have API access.
  • pracas
    @Kailash can you add some php examples for retrieving quotes? modifying orders, etc?
  • pracas
    pracas edited May 2016
    Both examples are for placing orders. Btw I've figured most of it, going through the php code.
    Can you tell me how to retrieve INDIA VIX ?
  • Kailash
    @pracas Looks like there are some issues with INDIAVIX. We'll fix this shortly and let you know.
  • amanrawat
    Our main requirement is to get updated market rates, so we opted for Kite.Trade Websockets, We have successfully connected to websockets using login authentication flow and grabbing public_token.

    Question is, it possible to do that without login authentication flow is it possible to get the public_token which can be used anywhere in client app (like in mobile apps) or server side, so that we can push updated market price for specific STOCK (instrument).

    Please revert in this regard
  • Kailash
    It's not possible to access any of the APIs without authentication.
  • amanrawat
    Hi Kailash, thanks for your revert, we've an app (IOS and android) we want to reflect live market prices there, and have a single Kite Connect account, we want to use that account to authenticate all users, would that be acceptable by kite terms of use and is there multi session allowed?
  • Kailash
    Hi @amanrawat , multi-user login is possible if you are building a platform (but it'll need exchange approvals). Please e-mail [email protected] regarding getting empanelled as a startup.
Sign In or Register to comment.