Twilio SMS (Java)执行失败



我正在尝试用Twilio发送短信。我遵循了所有的说明,并设置了JAVA_HOME环境变量。当我运行程序时,我得到:

任务':StockAlertClass:SMS.main()'执行失败。

Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_212。jdk/Contents/Home/bin/java " finished with非零退出值1

  • 试题:使用——info或——debug选项运行以获得更多的日志输出。运行——scan以获得完整的见解。

  • 异常:org.gradle.api.tasks.TaskExecutionException: task ':StockAlertClass:SMS.main()'执行失败。<36个内部呼叫>org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_212。jdk/Contents/Home/bin/java " finished with非零退出值1<98 internal calls>

我的java类是

import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.type.PhoneNumber;
public class SMS {
// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
public static final String ACCOUNT_SID = System.getenv("HiddenForPrivacy");
public static final String AUTH_TOKEN = System.getenv("HiddenForPrivacy");
public static void Message() {
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
Message message = Message.creator(new PhoneNumber("+HiddenForPrivacy"),
new PhoneNumber("HiddenForPrivacy"),
"Test ").create();
System.out.println(message.getSid());
}
public static void main(String[] args) {
Message();
}
}

构建。它是:

plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
mavenLocal()
}
if (hasProperty('buildScan')) {
buildScan {
termsOfServiceUrl = 'https://gradle.com/terms-of-service'
termsOfServiceAgree = 'yes'
}
}
dependencies {
compile 'org.slf4j:slf4j-simple:1.6.+'
compile 'com.sparkjava:spark-core:2.5.+'
implementation group: "com.twilio.sdk", name: "twilio", version: "8.21.0"
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
// https://mvnrepository.com/artifact/com.twilio.sdk/twilio
runtimeOnly group: 'com.twilio.sdk', name: 'twilio', version: '8.21.0'
}
test {
useJUnitPlatform()
}

这里是Twilio开发者布道者。

我关心的是你是如何分享这些台词的:

public static final String ACCOUNT_SID = System.getenv("HiddenForPrivacy");
public static final String AUTH_TOKEN = System.getenv("HiddenForPrivacy");

您不应该在这些行中隐藏键。相反,您应该将帐户SID和认证令牌设置为称为ACCOUNT_SIDAUTH_TOKEN的环境变量,然后您的代码应该看起来像:

public static final String ACCOUNT_SID = System.getenv("ACCOUNT_SID");
public static final String AUTH_TOKEN = System.getenv("AUTH_TOKEN");

如果你在这些调用中使用了实际的Account Sid和Auth Token,那么我的猜测是你的代码失败了,因为它们没有正确设置。

我推荐阅读这篇关于在Java中使用环境变量的博文以获得更多细节。

相关内容

  • 没有找到相关文章

最新更新