Lasan Lasan - 5 months ago 62
Java Question

Twilio sms sending giving errors , using java

I am try to send sms from my phone number to my phone number .
it gives me errors telling that : "Exception in thread "main" com.twilio.exception.ApiException: The requested resource /2010-04-01/Accounts/myaccountusername@gmail.com/Messages.json was not found"

public static void main(String[] args) {
Twilio.init("myaccountusername@gmail.com", "mypassword");
Message message = Message.creator(new PhoneNumber("+947XXXXXXXX"),
new PhoneNumber("+947XXXXXXXX"), "This is the ship that made the Kessel Run in fourteen parsecs?").create();

System.out.println(message.getSid());
}


I am new to this twilio . I need expert to tell me what is the reason for this exception and how to fix it

Answer Source

It is Twilio.init(ACCOUNT_SID, AUTH_TOKEN); not Twilio.init("myaccountusername@gmail.com", "mypassword");

You can't use your email address and your password. You can find the correct values for your ACCOUNT_SID and AUTH_TOKEN on dashboard after you login into Twilio Console at https://www.twilio.com/console

enter image description here

Twilio docs https://www.twilio.com/docs/libraries/java#testing-your-installation

// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.type.PhoneNumber;

public class Example {
  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) {
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    Message message = Message.creator(new PhoneNumber("+15558675309"),
        new PhoneNumber("+15017250604"), 
        "This is the ship that made the Kessel Run in fourteen parsecs?").create();

    System.out.println(message.getSid());
  }
}