使用SmartyStreets,但什么都不起作用。

huangapple go评论96阅读模式
英文:

Using SmartyStreets and nothing is working

问题

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

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
英文:

I am using the SmartyStreets API to verify valid street addresses in New York City.
I downloaded their example code file and I tried running it with a variety of different values. I tried my address, the address of Apples HQ, and even the stock address they had preloaded and nothing is working. This is the Example class and it is the shortest template of them all.

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++;
    }
}

The message I am supposed to get after running this main method is:

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

But instead I am getting this and an error code:

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

答案1

得分: 4

以下是已翻译的内容:

解决方案:
我私下收到了解决我的问题的以下解决方案,我认为这位提供解决方案的人是该程序的开发者。

请前往以下链接:
https://account.smartystreets.com/#keys

登录并滚动到页面底部,那里会显示自动生成的部分。
您需要从这里获取 auth-id 和 auth-token 的值,然后将它们用于替换示例类中的虚拟值。

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

英文:

SOLUTION:
I received the following solution for my problem privately with whom I assume is a developer for the program.

Go to the following link
https://account.smartystreets.com/#keys

Login and scroll to the bottom of the page where it says auto-generated.
You must take the auth-id and auth-token values from here and use them to replace the dummy values in the Example class.

At this point you are able to test out whatever addresses you want in USA.
For rulings on what combinations and parts of addresses are required check this link:
https://smartystreets.com/docs/cloud/us-street-api#root

huangapple
  • 本文由 发表于 2020年7月31日 10:44:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/63185032.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定