[英]Phone Verification with the Twilio API using java
Implementing authentication in a project and using phone verification with the Twilio API but have run into an error that I later carried a simple test with code I have added below .在项目中实现身份验证并使用 Twilio API 进行电话验证但遇到了一个错误,我后来使用我在下面添加的代码进行了一个简单的测试。 Did a basic test with sample code I got from the official twilio documentation from their site and had this error which I haven't been able to figure out.
使用我从他们网站的官方twilio 文档中获得的示例代码进行了基本测试,并且出现了我无法弄清楚的错误。
Here is the sample code.
这是示例代码。
import com.twilio.Twilio;
import com.twilio.rest.verify.v2.service.Verification;
public class Login {
public final static String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
public final static String AUTH_TOKEN = "auth_token";
public static void main(String[] args) {
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
Verification verification = Verification.creator(
"VAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"+237677777777",
"sms")
.create();
System.out.println(verification.getStatus());
}
}
Here is the error
这是错误
/usr/lib/jvm/java-1.8.0-openjdk-amd64/bin/java -javaagent:/snap/intellij
Exception in thread "main" com.twilio.exception.ApiException: Cannot deserialize instance of `java.util.LinkedHashMap<java.lang.Object,java.lang.Object>` out of START_ARRAY token
at [Source: (ByteArrayInputStream); line: 1, column: 100] (through reference chain: com.twilio.rest.verify.v2.service.Verification["send_code_attempts"])
at com.twilio.rest.verify.v2.service.Verification.fromJson(Verification.java:167)
at com.twilio.rest.verify.v2.service.VerificationCreator.create(VerificationCreator.java:201)
at com.twilio.rest.verify.v2.service.VerificationCreator.create(VerificationCreator.java:23)
at com.twilio.base.Creator.create(Creator.java:45)
at Login.main(Login.java:14)
Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.LinkedHashMap<java.lang.Object,java.lang.Object>` out of START_ARRAY token
at [Source: (ByteArrayInputStream); line: 1, column: 100] (through reference chain: com.twilio.rest.verify.v2.service.Verification["send_code_attempts"])
at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59)
at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1442)
at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1216)
at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1126)
at com.fasterxml.jackson.databind.deser.std.StdDeserializer._deserializeFromEmpty(StdDeserializer.java:639)
at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:360)
at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:29)
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:530)
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeWithErrorWrapping(BeanDeserializer.java:528)
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:417)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1287)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:326)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:159)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4202)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3242)
at com.twilio.rest.verify.v2.service.Verification.fromJson(Verification.java:165)
... 4 more
Process finished with exit code 1
Please any help will be much appreciated, im new to Twilio.请任何帮助将不胜感激,我是 Twilio 的新手。
Halo found a walk around this bug. Halo 发现了一个绕过这个错误的方法。 In the meanwhile, while Twilio handles that you can use this way to get the verification code if you are facing same issue :)
同时,虽然 Twilio 处理,如果您遇到相同的问题,您可以使用这种方式获取验证码 :)
I used the java Process class and the curl to post我使用了 java Process 类和curl 来发布
Here is the code.这是代码。
void method(String var) throws IOException {
String command ="curl -X POST https://verify.twilio.com/v2/Services/" + SERVICE_ID + "/Verifications --data-urlencode To=" + phoneNumber +
" --data-urlencode Channel=sms -u " + ACCOUNT_SID + ":" + AUTH_TOKEN;
Process process = Runtime.getRuntime().exec(command);
process.getInputStream();
// some code
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.