java - 使用 SmartyStreets 但没有任何效果

标签 java spring-boot maven street-address smartystreets

我正在使用 SmartyStreets API 验证纽约市的有效街道地址。 我下载了他们的示例代码文件,并尝试使用各种不同的值来运行它。我尝试了我的地址、苹果总部的地址,甚至他们预加载的股票地址,但都没有用。 这是 Example 类,它是所有模板中最短的。

public class Example {
public static void main(String[] args) throws IOException, SmartyException {
    // This keypair will have been deleted by the time you are watching this video...
    String authId = "d418a4cc-69da-e48f-bc9d-ee7357b30d61";
    String authToken = "clDiwTlcW5YTFjEl5mp1";

    System.out.println("Step 0. Wire up the client with your keypair.");
    Client client = new ClientBuilder(authId, authToken).buildUsStreetApiClient();

    System.out.println("Step 1. Make a lookup. (BTW, you can also send entire batches of lookups...)");
    Lookup lookup = new Lookup();
    lookup.setStreet("1 Rosedale");
    lookup.setLastline("Baltimore MD");
    lookup.setMaxCandidates(10);

    System.out.println("Step 2. Send the lookup.");
    client.send(lookup);

    System.out.println("Step 3. Show the resulting candidate addresses:");
    int index = 0;
    for (Candidate candidate : lookup.getResult()) {
        System.out.printf("- %d: %s, %s\n", index, candidate.getDeliveryLine1(), candidate.getLastLine());
        index++;
    }
}

运行这个主要方法后我应该得到的消息是:

Step 0. Wire up the client with your keypair.
Step 1. Make a lookup. (BTW, you can also send entire batches of lookups...)
Step 2. Send the lookup.
Step 3. Show the resulting candidate addresses:
- 0: 1 N Rosedale St, Baltimore MD 21229-3737
- 1: 1 S Rosedale St, Baltimore MD 21229-3739

但我得到的是这个和一个错误代码:

Step 0. Wire up the client with your keypair.
Step 1. Make a lookup. (BTW, you can also send entire batches of lookups...)
Step 2. Send the lookup.
Exception in thread "main" com.smartystreets.api.exceptions.BadCredentialsException: Unauthorized: The credentials were provided incorrectly or did not match any existing, active credentials.
    at com.smartystreets.api.StatusCodeSender.send(StatusCodeSender.java:21)
    at com.smartystreets.api.SigningSender.send(SigningSender.java:18)
    at com.smartystreets.api.URLPrefixSender.send(URLPrefixSender.java:19)
    at com.smartystreets.api.RetrySender.trySend(RetrySender.java:34)
    at com.smartystreets.api.RetrySender.send(RetrySender.java:23)
    at com.smartystreets.api.us_street.Client.send(Client.java:48)
    at com.smartystreets.api.us_street.Client.send(Client.java:27)
    at examples.Example.main(Example.java:25)

Process finished with exit code 1

最佳答案

解决方案: 我私下收到了针对我的问题的以下解决方案,我认为是该程序的开发人员。

转到以下链接 https://account.smartystreets.com/#keys

登录并滚动到显示自动生成的页面底部。 您必须从此处获取 auth-id 和 auth-token 值,并使用它们替换 Example 类中的虚拟值。

此时您可以在美国测试您想要的任何地址。 有关需要哪些地址组合和部分地址的规则,请查看此链接: https://smartystreets.com/docs/cloud/us-street-api#root

关于java - 使用 SmartyStreets 但没有任何效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63185032/

相关文章:

java - maven,执行标签,id 标签丢失

jsp - 从 JSP 引用 js maven 依赖项

java - 组合 JPA、EJB 和 JSF 托管 bean 的首选设计模式是什么?

Java 为什么我不能在函数式接口(interface)中使用多重继承

java - 正则表达式匹配模式和匹配项

Java消息对象枚举Spring集成错误

java - Maven 传递依赖 - Commons Collection 版本 3 与 4

java - 我的 java 代码中的这个打印函数有什么问题?

android - 使用 Google + Facebook 登录的 Android 应用程序的 Spring boot REST api 安全性

hibernate - 如何在 Spring Boot 中使用 Spring 管理的 Hibernate 拦截器?