简体   繁体   English

导入 com.twilio.Twilio 无法解析

[英]The import com.twilio.Twilio cannot be resolved

I want to use the Twilio API to allow users from my web application to make calls or send messages.我想使用 Twilio API 来允许来自我的 Web 应用程序的用户拨打电话或发送消息。 So far I only wrote this basic code:到目前为止,我只写了这个基本代码:

import com.twilio.sdk.TwilioRestClient;
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Call;
import com.twilio.type.PhoneNumber;

public class Main {

      public static final String ACCOUNT_SID = "ACXX";
      public static final String AUTH_TOKEN = "XX";

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

            Call call = Call.creator(new PhoneNumber("+40742000000"), new PhoneNumber("+40742000000),
                new URI("http://demo.twilio.com/docs/voice.xml")).create();

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

This is the place where my JAR is stored now(the end of Referenced Libraries)这是我现在存储 JAR 的地方(引用库的结尾) 在此处输入图片说明

It just says that the imports Twilio cannot be resolved.它只是说无法解决进口 Twilio。 I have Java version 8, so it should be working like this.我有 Java 版本 8,所以它应该像这样工作。 I also download the JARs and followed the instalation from this page.我还下载了 JAR 并按照页面的安装进行了操作。 Still not working.还是行不通。 Does any of you have an idea how to make it work?你们有没有人知道如何使它工作?

Twilio developer evangelist here. Twilio 开发人员布道者在这里。

If you are using the version 7 Twilio Java library then you no longer need to import com.twilio.sdk.TwilioRestClient;如果您使用的是版本 7 Twilio Java 库,那么您不再需要import com.twilio.sdk.TwilioRestClient; . . In fact, that is no longer there, so this might be causing your import issues.事实上,它不再存在,所以这可能会导致您的导入问题。

Also, make sure you have only one version of the JAR in your project.此外,请确保您的项目中只有一个版本的 JAR。 And make sure to keep up to date, the current version, as of writing, is 7.14.4 .并确保保持最新状态,截至撰写本文时,当前版本为7.14.4

Check out the docs on making a call with Twilio in Java .查看有关在 Java 中使用 Twilio 进行调用的文档。 You'll find the example looks like this:您会发现示例如下所示:

import java.net.URI;
import java.net.URISyntaxException;

import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Call;
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 = "your_account_sid";
  public static final String AUTH_TOKEN = "your_auth_token";

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

    Call call = Call.creator(new PhoneNumber("+14155551212"), new PhoneNumber("+15017250604"),
        new URI("http://demo.twilio.com/docs/voice.xml")).create();

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

Give that a go and let me know if it helps.试一试,如果有帮助,请告诉我。

If anyone trying to use twilio [ I am using with spring boot ], please always make sure you pick up the latest version <version>7.50.1</version> as of now.如果有人尝试使用 twilio [我正在使用 spring boot ],请始终确保您选择最新版本<version>7.50.1</version>到目前为止。

I used earlier version and it didn't work.我使用了较早的版本,但它不起作用。 As soon as I upgraded that to 7.50.1 it worked.一旦我将其升级到7.50.1,它就起作用了。 I hope it helps you.我希望它能帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM