Invalid session credentials response while access token exchange on Android

chamu
chamu edited August 2017 in Mobile and Desktop apps
Hi,
I subscribed to a Kite connect account. I am trying to access kite API from an Android application. I loaded the webview for login and got back the request token to my rediect url. However, when am calling the token API with respective request_token, api_key and checksum(SHA 256 of apikey+request token+secret api key). The API is throwing the following error:
{"status": "error", "message": "Invalid session credentials", "error_type": "TokenException"}

Following is the code am using for token API from Android:
               String hashableText = apikey + requestToken + secretkey;
String sha256hex = new String(DigestUtils.sha256(hashableText));

List<NameValuePair> params = new ArrayList();
params.add(new BasicNameValuePair("api_key", apikey));
params.add(new BasicNameValuePair("request_token", requestToken));
params.add(new BasicNameValuePair("checksum", sha256hex));
httppost.setEntity(new UrlEncodedFormEntity(params));
Note:
1. I tired (Hex.encodeHex(DigestUtils.sha256(hashableText))); and (DigestUtils.sha256(hashableText)) both
2. I tried using the Java SDK from Android, but the following error is thrown

java.lang.NoSuchMethodError: No static method encodeHexString([B)Ljava/lang/String; in class Lorg/apache/commons/codec/binary/Hex; or its super classes (declaration of 'org.apache.commons.codec.binary.Hex' appears in /system/framework/org.apache.http.legacy.boot.jar)
at org.apache.commons.codec.digest.DigestUtils.sha256Hex(DigestUtils.java:532)
at com.rainmatter.kiteconnect.KiteConnect.requestAccessToken(KiteConnect.java:162)

Please Help!

Thanks
  • sujith
    Hi @chamu,
    javakiteconnect will not work for the android app since it is using Unirest API for making network calls. You need to find an alternate for Unirest in android like Okhttp, Volley or Retrofit.

    In the above code, I think, you have different version of
    DigestUtils
    , try including import org.apache.commons.codec.digest.DigestUtils; in your project dependency.
    For reference, you can check out code here.
  • chamu
    Thank you Sujith
This discussion has been closed.