Undefined property error for Inalidate Access Token

anbu369
anbu369 edited February 2018 in PHP client
Hi,
I am trying to invalidate my access token using the following method

$this->kite->invalidateAccessToken();

But I get the following error
"Undefined property: App\Services\KiteConnect::$my_access_token"
I get the above error with my access token and a dollar symbol infront of it.

But other Api calls are working fine like getProfile() and getMargins()

What could be wrong here? Am I doing it right or should I send any additional parameters?

Thanks,
Anbu
  • sujith
    Can you post your code here?
  • anbu369
    anbu369 edited February 2018
    @sujith

    Here is my code. I am using it in a laravel framework

    this is my conbstruct
    public function __construct()
    {
    $this->api_key = Config::get('kite.KITE_API_KEY');
    $this->api_secret = Config::get('kite.KITE_API_SECRET');
    $this->kite = new KiteConnect($this->api_key);

    $this->middleware(function ($request, $next) {
    if (Session::has('KITE_ACCESS_TOKEN')) {
    $this->kite->setAccessToken(Session::get('KITE_ACCESS_TOKEN'));
    }
    return $next($request);
    });
    }
    this is my login function
    public function login()
    {
    if (Session::has('KITE_ACCESS_TOKEN')) {
    return Redirect::route('welcome');
    } else {
    return Redirect::to($this->kite->getLoginURL());
    }
    }
    My getaccesscode function
    public function getAccessToken(Request $request)
    {
    $request_token = $request->query()['request_token'];

    try {
    $user = $this->kite->generateSession($request_token, $this->api_secret);
    $this->kite->setAccessToken($user->access_token);
    Session::put('KITE_ACCESS_TOKEN', $user->access_token);
    return Redirect::route('welcome');
    } catch (Exception $e) {
    Log::info($e->getMessage());
    throw $e;
    }
    }
    Everything works until here, I can get the user and all the information. I want to invalidate the access toke when logging out. here is my logout function
    public function logout()
    {
    $this->kite->invalidateAccessToken();
    Session::flush('KITE_ACCESS_TOKEN');
    return Redirect::route('welcome');
    }
    But I get the following error when the logout function is called

    Undefined property: App\Services\KiteConnect::$my_access_token

    -Sorry I dont know how to have indentations in the code block here
  • tonystark
    @anbu369 Do you have "$my_access_token" as anywhere in your code?
Sign In or Register to comment.