Yogesh Seralia
Yogesh Seralia

Reputation: 350

Twilio - getting ERROR : Account SID cannot be null when making a call

I am getting this exception sometimes when app remains active for long time. Could any one tell,whats the problem ?

Connecting call failed

java.lang.IllegalArgumentException: Account SID cannot be null when making a call
                                                          at com.twilio.client.impl.MakeCallCommand.<init>(MakeCallCommand.java:33)
                                                          at com.twilio.client.impl.CallControlManager.makeCall(CallControlManager.java:423)
                                                          at com.twilio.client.impl.InternalConnectionImpl.connect(InternalConnectionImpl.java:212)
                                                          at com.twilio.client.impl.DeviceImpl$2.onCompletion(DeviceImpl.java:339)
                                                          at com.twilio.client.impl.MediaManager.onPlayComplete(MediaManager.java:279)
                                                          at com.twilio.client.impl.MediaManager.queueSound(MediaManager.java:173)
                                                          at com.twilio.client.impl.DeviceImpl.connect(DeviceImpl.java:335)
                                                          at com.lola.activities.CallingActivity.connect(CallingActivity.java:199)
                                                          at com.lola.activities.CallingActivity.onCreate(CallingActivity.java:92)
                                                          at android.app.Activity.performCreate(Activity.java:5122)
                                                          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
                                                          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
                                                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
                                                          at android.app.ActivityThread.access$600(ActivityThread.java:162)
                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
                                                          at android.os.Handler.dispatchMessage(Handler.java:107)
                                                          at android.os.Looper.loop(Looper.java:194)
                                                          at android.app.ActivityThread.main(ActivityThread.java:5371)
                                                          at java.lang.reflect.Method.invokeNative(Native Method)
                                                          at java.lang.reflect.Method.invoke(Method.java:525)
                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
                                                          at dalvik.system.NativeStart.main(Native Method)

**EDIT : ** here is connect() method called when Call Button is clicked :

public void connect(String fromMobileNo, String phoneNumber)
    {

        Map<String, String> parameters = new HashMap<String, String>();

        parameters.put("frommobileno", fromMobileNo);
        parameters.put("mobileno",  phoneNumber);

        Log.d("parameters", parameters + "");
        Log.d(TAG, "device :" + device);
        Log.d(TAG, "device :" + device);

        if(device == null)
        {
            Toast.makeText(getApplicationContext(),"Sorry from our side.Please try again.",Toast.LENGTH_LONG).show();
            finish();
        }
        else{
            connection = device.connect(parameters, (Controller)getApplication()/* ConnectionListener */);

            if (connection == null && ((Controller)getApplication()).basicConnectionListener != null)
                ((Controller)getApplication()).basicConnectionListener.onConnectionFailedConnecting(new Exception("Couldn't create new connection"));

        }

        if (connection != null){
            Controller.setConnection(connection);


        }else {
            Log.w(TAG, "Failed to create new connection");
        }

    }

Upvotes: 1

Views: 5092

Answers (3)

Born Ready
Born Ready

Reputation: 3496

C# Users

Setup your TWILIO credentials as environment variables.

Check here : Add environment variables Windows

Call them as follow :

    string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
    string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");

Then execute the program.

Upvotes: 0

you have to use this twilio console for your account sid and auth token instead of this!

[Edit]: The second link is the old twilio user panel which I think is being redirected to the new one from exactly the date that I am editing this answer(!) which is the first link in above. retrying getting new account sid and the auth token again using the new user panel control(www.twilio.com/console) solved the problem for me.

Upvotes: -1

Ijas Ahamed N
Ijas Ahamed N

Reputation: 6100

Capability token has a life time. Its gets expired after it. I think, this issue is with expiration of your capability token.

So update your capability token to solve this issue.

Check out this

Follow below steps to overcome this problem

Step 1 : First try to check the state of your device before making out calls.

Check device state

Step 2 : If your device is OFFLINE, try to update token. If READY, call. If BUSY, dont call.

Device State Values

Upvotes: 3

Related Questions