Orest
Orest

Reputation: 1897

Can't create Twilio ChatClient on android

I'm trying to build chat application on Android and I've stuck on a very first step. I can't create ChatClient. According to documentation I should call some method like this:

ChatClient.create(context.getApplicationContext(), token, props, myCallback);

Unfortunately I'm receiving error: "Invalid access token grants", you can check this link for error details.

I've verified what's inside my jwt access token and it seems that everything is OK with grants. I've used https://jwt.io/ debugger to test it and could see the following payload(I've dashed my credentials to show only structure):

{ "iss": "SK####################",
  "exp": 1516198358,
   "jti": "SK#####################", 
   "sub": "######################", 
   "grants": { 
         "identity": "[email protected]", 
         "chat": { 
             "service_sid": "###################",
             "endpoint_id": "###################"
         } 
    }
 }

I've checked all the values and they seem to be OK, I've also tried to copy this token and pass it to my web(JS) project and was able to sign in without any issues which proves that token itself should be OK.

Any help appreciated, thanks

Upvotes: 1

Views: 166

Answers (2)

Berkus
Berkus

Reputation: 345

So the solution was to use correct region setting, because tokens in one region are incompatible with services from another.

Error messages on the service side are being refined to better reflect this case.

Upvotes: 1

Berkus
Berkus

Reputation: 345

please do not use "endpoint_id" in the grants, it has been deprecated and may be throwing off some service validation logic.

If you continue getting this error please contact support.twilio.com and provide adb logs and the token itself (do not paste it here publicly). Also see https://github.com/twilio/twilio-chat-demo-android/blob/master/REPORT_BUGS.md

Upvotes: 1

Related Questions