Search code examples
androidchattwilio

Integrate Twilio chat function in ANDROID


I made an account on Twilio console for accessing their Chat services. I generated a access token with "client Identity" as its reference name.

I downloaded the project from https://github.com/twilio/twilio-chat-demo-android.

After performing requisite steps such as gradle file sync and adding google-services.json

I am unable to figure out what could be the URL ?

def ACCESS_TOKEN_SERVICE_URL = project.hasProperty(ACCESS_TOKEN_SERVICE_URL) ? "\""+project.getProperty(ACCESS_TOKEN_SERVICE_URL)+"\"" :"\"http://localhost:8000/token.php/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImN0eSI6InR3aWxpby1mcGE7dj0xIn0.eyJqdGkiOiJTSzllOGRlODAwM2U3ZTdlMjk2NzY5ZWUxZTQ0MDJhNDkxLTE1MDA4OTE2ODgiLCJpc3MiOiJTSzllOGRlODAwM2U3ZTdlMjk2NzY5ZWUxZTQ0MDJhNDkxIiwic3ViIjoiQUNkZTFkZGJjYjZiYTE5MTBhMmExMDA2ZThmNTE1MDIzZiIsImV4cCI6MTUwMDg5NTI4OCwiZ3JhbnRzIjp7ImlkZW50aXR5IjoiY2hhdCIsImlwX21lc3NhZ2luZyI6eyJzZXJ2aWNlX3NpZCI6IklTM2E4OTVkNGQyNjdlNDZjNjgxZmU0NDBlZGZhNDkzZmUiLCJlbmRwb2ludF9pZCI6ImlwLW1lc3NhZ2luZy1kZW1vOmNoYXQ6ZGVtby1kZXZpY2UifX19.J5dkegxkoo9fWaN0embyAcShZ2831InLbuOX6JI8jvU\"" 

Since, I haven't setup a web service I am try to access through localhost.

After successfully installation of app, UI appears with login button along with edittext field with reference name, which I mention at Twilio console. On clicking the login button, my app crashes throwing an error message:

java.lang.IllegalStateException: Token cannot be null in ChatClient constructor

apparently, my url is not appropriate, if anyone have worked on Twilio chat application, please do guide me where I am wrong.


Solution

  • Twilio developer evangelist here.

    You need to setup a web application that can serve access tokens to your Android app. I would follow the instructions as part of the quickstart guide to starting Programmable Chat on Android.

    The instructions get you to install and run a PHP project that can generate access tokens for the various Twilio services. The instructions get you to run the application on localhost:8000. Once you have that application running your ACCESS_TOKEN_SERVICE_URL should be http://localhost:8000/token.php.

    Let me know if that helps at all.