Incorrect `api_key` or `access_token

write2onkar
write2onkar edited December 2019 in Java client
Hi,

I am using below JAVA code to connect using kite API. But, I am getting error. Can you please check and revert ASAP?
kiteConnect = new KiteConnect(ApiKey);
kiteConnect.setUserId(UserId);
kiteConnect.setAccessToken(AccessToken);
kiteConnect.setPublicToken(PublicToken);
kiteConnect.setEnableLogging(setEnableLogging);

try
{
System.out.println("email: " + kiteConnect.getProfile().email);
}
catch (JSONException | IOException | KiteException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
Dec 06, 2019 9:38:15 AM okhttp3.internal.platform.Platform log
INFO: --> GET https://api.kite.trade/user/profile
Dec 06, 2019 9:38:15 AM okhttp3.internal.platform.Platform log
INFO: User-Agent: javakiteconnect/3.0.0
Dec 06, 2019 9:38:15 AM okhttp3.internal.platform.Platform log
INFO: X-Kite-Version: 3
Dec 06, 2019 9:38:15 AM okhttp3.internal.platform.Platform log
INFO: Authorization: token clkki4gg91pqssa5qzn:K7cGqH0q8dVHgOeIPtNCV7Gmhcpc4ScA
Dec 06, 2019 9:38:15 AM okhttp3.internal.platform.Platform log
INFO: --> END GET
Dec 06, 2019 9:38:16 AM okhttp3.internal.platform.Platform log
INFO: <-- 403 https://api.kite.trade/user/profile (352ms)
Dec 06, 2019 9:38:16 AM okhttp3.internal.platform.Platform log
INFO: date: Fri, 06 Dec 2019 04:06:25 GMT
Dec 06, 2019 9:38:16 AM okhttp3.internal.platform.Platform log
INFO: content-type: application/json
Dec 06, 2019 9:38:16 AM okhttp3.internal.platform.Platform log
INFO: set-cookie: __cfduid=d47b88cacce4896afec3fb2dad0a9fc6e1575605185; expires=Sun, 05-Jan-20 04:06:25 GMT; path=/; domain=.kite.trade; HttpOnly
Dec 06, 2019 9:38:16 AM okhttp3.internal.platform.Platform log
INFO: cf-cache-status: DYNAMIC
Dec 06, 2019 9:38:16 AM okhttp3.internal.platform.Platform log
INFO: strict-transport-security: max-age=15552000; includeSubDomains
Dec 06, 2019 9:38:16 AM okhttp3.internal.platform.Platform log
INFO: expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Dec 06, 2019 9:38:16 AM okhttp3.internal.platform.Platform log
INFO: server: cloudflare
Dec 06, 2019 9:38:16 AM okhttp3.internal.platform.Platform log
INFO: cf-ray: 540b631c2d19e15e-BOM
Dec 06, 2019 9:38:16 AM okhttp3.internal.platform.Platform log
INFO:
Dec 06, 2019 9:38:16 AM okhttp3.internal.platform.Platform log
INFO: {"status":"error","message":"Incorrect `api_key` or `access_token`.","data":null,"error_type":"TokenException"}
Dec 06, 2019 9:38:16 AM okhttp3.internal.platform.Platform log
INFO: <-- END HTTP (111-byte body)
com.zerodhatech.kiteconnect.kitehttp.exceptions.TokenException
at com.zerodhatech.kiteconnect.kitehttp.KiteResponseHandler.dealWithException(KiteResponseHandler.java:48)
at com.zerodhatech.kiteconnect.kitehttp.KiteResponseHandler.handle(KiteResponseHandler.java:20)
at com.zerodhatech.kiteconnect.kitehttp.KiteRequestHandler.getRequest(KiteRequestHandler.java:53)
at com.zerodhatech.kiteconnect.KiteConnect.getProfile(KiteConnect.java:220)</blockquote>
  • sujith
    You can refer to this thread.
  • write2onkar
    Dear Sujith,
    I checked the thread, and I am doing everything right. I have used Kite API before. In fact, I was using the same code 5-6 months back and it was working correctly at that time. Then I discontinued the subscription for some reason. Now, I restarted the subscription yesterday, and the same code is not working since yesterday. Can you please check with your backend team if I am "enabled" for API service in their system/database?
  • sujith
    You seem to have created a new app. I would suggest checking your api_key and access token again.
    Everything seems fine with your app.
  • write2onkar
    That is correct, I have created a new APP. And checked my api_key and access token again. Still not working. Please check with your backend team if I am "enabled" from their side.

    KiteConnect kc = new KiteConnect(apiKey);
    kc.setEnableLogging(true);
    kc.setUserId(id);
    kc.setAccessToken(accessToken);
    kc.setPublicToken(publicToken);
    Profile p = kc.getProfile();

    Dec 06, 2019 12:16:51 PM okhttp3.internal.platform.Platform log
    INFO: {"status":"error","message":"Incorrect `api_key` or `access_token`.","data":null,"error_type":"TokenException"}
  • write2onkar
    Hello,

    I tried this again by writting a fresh code from scratch. Still the same error. Can someone please help?
  • sujith
    @write2onkar,
    There is no issue with the code. It is the access token that seems wrong. Since api_key, you have specified is right in the above comment.

    PS: Please don't post your app or user-related keys on public threads. If you have to do then I would suggest using the private message feature.
  • sujith
    Are you sure, you are generating an access token?
Sign In or Register to comment.