简体   繁体   English

Nexmo 2FA 不工作/存在错误,依赖项不包括接收代码和验证代码所需的一些方法

[英]Nexmo 2FA is not working/ is bugged, dependency doesn't include some methods needed for recieving the code and verifying it

The tutorial showed at https://dashboard.nexmo.com/getting-started/verify says that everything should work by coding: https://dashboard.nexmo.com/getting-started/verify上显示的教程说一切都应该通过编码来工作:

1   NexmoClient client = NexmoClient.Builder()
2     .apiKey("HIDDEN-CODE-I-CANNOT-SHOW")
3     .apiSecret("HIDDEN-CODE-I-CANNOT-SHOW")
4     .build();
5   VerifyClient verifyClient = client.getVerifyClient();
6
7   VerifyRequest request = new VerifyRequest("HIDDEN-CODE-I-CANNOT-SHOW", "HIDDEN-CODE-I-CANNOT-SHOW");
8   request.setLength(4);
9   
10   VerifyResponse response = verifyClient.verify(request);
11
12   if (response.getStatus() == VerifyStatus.OK) {
13       System.out.printf("RequestID: %s", response.getRequestId());
14   } else {
15       System.out.printf("ERROR! %s: %s",
16         response.getStatus(),
17         response.getErrorText()
18       );
19   }

My problem/bug is the next:我的问题/错误是下一个:

request.SETLENGHT(4);
response.GETSTATUS();

These two lines of code (8-12) are red (the caracters that are in capital letters only).这两行代码 (8-12) 是红色的(只有大写字母的字符)。 If i leave my cursor on them it displays a message " Cannot resolve symbol 'setLength' " and " Cannot resolve symbol 'getStatus' " respectively.如果我将 cursor 留在上面,它会分别显示一条消息“无法解析符号'setLength' ”和“无法解析符号'getStatus' ”。

I tought somebody had the same problem as i did, but it wasn't the case.我坚持有人和我有同样的问题,但事实并非如此。 I have entered the repository of the developer of the nexmo library and the two functions are written on there (I'm trying to say that they exist), but in my program they weren't founded.我已经进入了nexmo库开发者的存储库,两个函数都写在那里(我想说它们存在),但是在我的程序中它们没有被创建。

These are the repositories of the developers:这些是开发人员的存储库:

  1. https://github.com/Nexmo/nexmo-java https://github.com/Nexmo/nexmo-java
  2. https://github.com/Nexmo/nexmo-java/blob/master/src/main/java/com/nexmo/client/verify/VerifyRequest.java https://github.com/Nexmo/nexmo-java/blob/master/src/main/java/com/nexmo/client/verify/VerifyRequest.java
  3. https://github.com/vonage/vonage-java-sdk https://github.com/vonage/vonage-java-sdk

In the first one they say and i quote "We recommend users begin migrating over to the Vonage Java Server SDK. If you have any questions, feel free to reach out to us at devrel@vonage.com or through our Community Slack at https://developer.nexmo.com/community/slack" As they said i did try to migrate to the new version of the project but the problem of that two lines preserves there too. In the first one they say and i quote "We recommend users begin migrating over to the Vonage Java Server SDK. If you have any questions, feel free to reach out to us at devrel@vonage.com or through our Community Slack at https: //developer.nexmo.com/community/slack"正如他们所说,我确实尝试迁移到项目的新版本,但是这两行的问题也仍然存在。

The second link shows some funtions written for the nexmo library.第二个链接显示了为 nexmo 库编写的一些函数。 From the line 315 to the line 323 you can see that the function ".setLenght" does exist because the developers created a builder for it, here is the code copied and pasted from that link:从第 315 行到第 323 行,您可以看到 function ".setLenght" 确实存在,因为开发人员为其创建了一个构建器,以下是从该链接复制和粘贴的代码:

    /**
     * @param length (optional) The length of the verification code to be sent to the user. Must be either 4 or 6. Use
     *               -1 to use the default value.
     * @return {@link Builder}
     */
    public Builder length(Integer length) {
        this.length = length;
        return this;
    }

What could be the problem?可能是什么问题呢? Libraries?图书馆? Compatibility?兼容性? I am using Apache Maven 3.6.3.我正在使用 Apache Maven 3.6.3。 This is my pom:这是我的pom:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.4.2</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
        <groupId>com.2FA</groupId>
        <artifactId>Auth-Two-Steps</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>Auth-Two-Steps</name>
        <description>Mini project to learn authentication</description>
        <properties>
            <java.version>11</java.version>
        </properties>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
    
            <dependency>
                <groupId>com.nexmo</groupId>
                <artifactId>client</artifactId>
                <version>5.6.0</version>
            </dependency>
    
    
            <dependency>
                <groupId>com.2FA</groupId>
                <artifactId>Auth-Two-Steps</artifactId>
                <version>0.0.1-SNAPSHOT</version>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    
    </project>

Those snippets would work on the nexmo 4.x SDK but will fail on the 5.x Nexmo SDK and 6.x Vonage SDK, it needs to be updated.这些片段可以在 nexmo 4.x SDK 上运行,但在 5.x Nexmo SDK 和 6.x Vonage ZF20E3C5E54C0AB3D375D660B3F6AZ 上会失败,需要更新。 See the code snippet - that will show you how to manage everything.查看代码片段- 这将向您展示如何管理所有内容。 setLength looks like it was removed when the builder pattern was added to Verify Request, you should use the builder pattern instead setLength看起来在将构建器模式添加到验证请求时已被删除,您应该改用构建器模式

eg例如

VerifyRequest request = VerifyRequest.builder("12018675309","acme").length(6).build();

getStatus() looks like it ought to work - if you continue to have problems you may want to make sure it's getting imported. getStatus()看起来应该可以工作 - 如果您仍然遇到问题,您可能需要确保它被导入。

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

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