Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用SmartyStreets时,一切都不起作用_Java_Spring Boot_Maven_Street Address_Smartystreets - Fatal编程技术网

Java 使用SmartyStreets时,一切都不起作用

Java 使用SmartyStreets时,一切都不起作用,java,spring-boot,maven,street-address,smartystreets,Java,Spring Boot,Maven,Street Address,Smartystreets,我正在使用SmartyStreets API验证纽约市的有效街道地址。 我下载了他们的示例代码文件,并尝试使用各种不同的值运行它。我尝试了我的地址,苹果总部的地址,甚至他们预装的股票地址,但什么都没用这是示例类,是所有示例类中最短的模板。 public class Example { public static void main(String[] args) throws IOException, SmartyException { // This keypair will have

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

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
但是我得到的却是这个和一个错误代码:

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
解决方案: 我私下收到了以下解决问题的方案,我假设他是该程序的开发人员

转到以下链接

登录并滚动到页面底部,显示自动生成。 您必须从这里获取auth id和auth令牌值,并使用它们替换示例类中的伪值

在这一点上,你可以测试出任何地址,你想在美国。 有关需要哪些地址组合和部分的裁决,请检查此链接:

您是否使用示例中显示的凭据?那些是无效的。他们被放在那里只是为了示威。您需要使用您自己的凭据。@Jeffrey我从哪里获得凭据,我应该使用我的站点登录名吗?如果是这样的话,我怎么把它转换成字符串呢